determining if the path point to file, directory or does not exist
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
@yegor256 take a look at this issue please and dispatch it somehow, see par.21
@sadovnikov how would you suggest fixing it?
@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 maybe we should also make a difference between them? to avoid that confusion. what do you think?
@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
Contentof the file orContent[](orList<Content>) of directory
Should I join http://www.teamed.io/ to implement this?
@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 :)
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.