pyfilesystem2
pyfilesystem2 copied to clipboard
Windows OSFS open function raises an fs.errors.FileExpected error when io.open raises a PermissionError
I am trying to create a method to tell if a file/folder is completely copied into a directory by some external user. This is proving to be REALLY difficult. As there needs to be filesystem independence, I have been researching different ways to detect this.
polling for a change in hash of a directory/file + the size of the file works well in Linux. This does not work on windows, as it appears windows must lock the file or something, meaning I can't read the file, so I cant do a hash of it. Further, for some reason getinfo(file_path)
always just returns the final expected size, as if the size metadata is used for size and its copied before any content, so I can't compare file sizes.
Another method I can think of is to try and open the file and catch some sort of exception, but the exception thrown by pyfs2 is a FileExpected
exception, which seems incorrect as I can guarantee that the path leads to a file (from my own testing), so I would have to remove the ability to actually detect when a directory is passed in which may lead to more bugs down the line.
The very last and my least favourite is just setting a 10 minute or so timer, then just saying "we done".
My testing shows that trying to open a readonly file for writing or writeonly file for reading produces a PermissionDenied
exception, which is what I'd expect so I am unsure why a mid-copy file on windows trying to be opened in read mode which I assume is locked by the windows OS produces a FileExpected
exception. It would make a lot more sense to produce a PermissionDenied
or FileLocked
exception.
Further, it may be valuable to create more PermissionDenied
like exceptions, eg ReadDenied
, WriteDenied
, FileLocked
, etc. I haven't thought about it a lot and I honestly don't know how this would be implemented into this. It quite possibly could be not possible given the assumptions we are required to make in pyfs2 :p, but at a minimum the PermissionDenied
for a mid-copy/transfer windows file I think is reasonable.
Additional question, if this is intended how can I replicate this in a unittest? I can't see anyway to get it to throw a FileExpected
exception when a file path is passed in.
but the exception thrown by pyfs2 is a FileExpected exception
This is due to #484 which I tried fixing in #491 but am having a very hard time doing so. The reason is a combination of Windows' stellar documentation (see discussion here) and overlap with POSIX error codes. Try what I might the Windows tests keep failing on AppVeyor. If you have any ideas that would be fantastic.
@willmcgugan and/or @althonos I'm inclined to believe this is a dupe of #484, albeit mixed in with some good feature requests?