amphp / file

An abstraction layer and non-blocking file access solution that keeps your application responsive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible inconsistency with EioDriver::unlink() and other functions

enumag opened this issue · comments

From reading the code today, I feel like they might be some inconsistencies in error handling between the drivers. For some operations some drivers can only return true or throw an exception while others might possibly return false but I'm not sure because I'm not familiar with eio and uv at all.

Most notably it seems that EioDriver::unlink() either returns true or throws an exception. Other drivers seem to can return false in some cases - possibly when file doesn't exist or there are insufficient permissions? If I'm correct about EioDriver being broken here then this would break FileCache::delete() as well.

Overall I think there should be more test cases for failures like these to ensure consistency between the drivers. For instance DriverTest has no test for calling unlink on a non-existent or insufficient-permissions file to ensure consistent result. Same goes for other functions most likely.

@kelunik There is definitely an issue with both chmod and chown. Some drivers return false on failure, others throw. What is correct?

@enumag I'd use the NativeDriver as reference implementation. If we need to change NativeDriver, I'd do that in v2.

@kelunik There is no NativeDriver. I assume you mean BlockingDriver?

Honestly I expected chown and chmod to behave similarly but that's not true for BlockingDriver.

Especially chown behavior makes no sense at all. It either returns true or throws but never returns false. It should either never throw or return Promise<void>. So yeah, we do actually need to change BlockingDriver as well.

I think we should fix this by revising the expected behavior for all functions first and then write appropriate tests, fix all the drivers and release v2.

I had the same thought yesterday, yes.

@kelunik @trowski Any news about amphp/file 2.0? I'm quite reluctant to use 1.0 because of the inconsistencies which are now fixed. Can I help with something else for 2.0?