Skip to content

Windows OSFS open function raises an fs.errors.FileExpected error when io.open raises a PermissionError #540

Open
@prchristie

Description

@prchristie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions