jcabi-github icon indicating copy to clipboard operation
jcabi-github copied to clipboard

determining if the path point to file, directory or does not exist

Open sadovnikov opened this issue 8 years ago • 7 comments

if "a_path" points to a directory, then contents().exists(a_path) returns true, however contents().get(a_path) throws class cast exception as mentioned in #903

In the current implementation, there is no way to test is a path belongs to a directory without throwing-and-catching an exception

sadovnikov avatar Mar 18 '16 15:03 sadovnikov

@yegor256 take a look at this issue please and dispatch it somehow, see par.21

dmarkov avatar Mar 22 '16 08:03 dmarkov

@sadovnikov how would you suggest fixing it?

yegor256 avatar Mar 28 '16 22:03 yegor256

@yegor256 actually there is #1217 for this... exists() still returns true for both directories and files. However contents().get(a_path) returns null for directories

Although it feels like a work around. Contents in GitHub API represent both directories and files, while in jcabi-github it's created for files only

sadovnikov avatar Mar 29 '16 09:03 sadovnikov

@sadovnikov maybe we should also make a difference between them? to avoid that confusion. what do you think?

yegor256 avatar Mar 29 '16 18:03 yegor256

@yegor256 not throwing an exception is a good step - thanks for merging #1217

Yes, I would change contents().get(a_path) to return an object with methods for

  • checking type of the path (directory or file) and
  • getting either Content of the file or Content[] (or List<Content>) of directory

Should I join http://www.teamed.io/ to implement this?

sadovnikov avatar Mar 30 '16 06:03 sadovnikov

@sadovnikov no, just submit a pull request and we'll review it and merge. Well, you can certainly try to join us by submitting this form: http://at.teamed.io/join.html :)

yegor256 avatar Mar 30 '16 20:03 yegor256

Not sure if this is the correct channel and I apologize in advance for that.

The contents.get(path,ref) makes a request every time it is invoked and thus the following example of retrieving all files and folders under a given path is inefficient.

for (final Content c : contents.iterate(dir, branch)) {
    if (contents.get(c.path(), branch) == null) {
        // Handle folder
    } else {
        // handle file
    }
}

The contents.iterate(dir, branch) retrieves all information and there is no point in making the same request again to determine whether a content is a file or folder.

What is the best (most efficient way) to retrieve all files under a given path (including those in the sub-folders)?

Can we modify the Content class and include a type (which is represents the JSON type files and seems to have one of the following values: file, dir and symlink)? This can be either an enum or another interface.

ghost avatar May 31 '17 16:05 ghost