I'm working on adding a new backend for a protocol I'm working on, and trying to understand the interface to Fs.List, specifically for indicating that the directory/file wasn't found.
The documentation for Fs.List says: "This should return ErrDirNotFound if the directory isn't found." I think it's referring to "ErrorDirNotFound", right?
Here are my questions:
What's the proper way to indicate to a caller of Fs.List that no results were found?
How do I know when to return ErrorDirNotFound vs ErrorObjectNotFound? It seems like there's no way to no whether the user is requesting a directory or file since directories can end in a slash or not, correct?
If the directory was found, but empty, then return an empty slice of entries.
Fs.List should always return ErrorDirNotFound.
If you look at the code for one of the other backends, you'll see the little dance they do to work out whether what the user supplied was a file or a directory.
Just to make sure I'm understanding, Fs.List should return ErrorDirNotFound even if the directory exists but the user attempted to list a file within that directory that does not exist?
Still trying to wrap my head around determining files vs directories.
My protocol currently requires that the client know ahead of time whether it's listing a file or dir, as dirs return a JSON listing but files require the use of HEAD (because otherwise it will return that actual file). The way the protocol keeps this straight is by specifying that directory names must end with a "/". I've been looking through the box code, but apparently their API is more forgiving where you can list any item and then check in the response to see whether it's a file or directory?
Are there any other backends which you could point me towards that have a similar restriction to my protocol?
My current approach for rclone is attempting to list the path as a directory, and if the request returns an error then try file, and if that fails return ErrorDirNotFound.
List doesn't take a file parameter, so it will return ErrorDirNotFound if the directory does not exist.
If you try and List a file, then exactly what error you get back is backend specific, but likely ErrorIsFile
Rclone always knows whether a file or a directory is expected in the backend interface, except in the NewFs command where rclone attempts to work out whether the argument passed points to a file or a directory.
So this shouldn't be a problem in practice.
The argument to List should always be a directory. If it isn't then your backend should return some error, but whatever the protocol gives back is fine.