Re: Trouble with GFile.enumerate_children() and permissions



On Thu, Jan 28, 2016 at 10:01 AM Per <pmknutsen gmail com> wrote:
Hi,
I am having some trouble reading a directory that contains files/directories with restrictive permissions. This is my code:

>>>>
let folder = Gio.file_new_for_path( path );
let children = folder.enumerate_children('*', 0, null, null);
while ((file_info = children.next_file(null, null)) !== null) {
  if (file_info.get_is_hidden()) { continue; }          // skip hidden files
  if (isDirectory(file_info)) { dirs.push(file_info); } // is directory
  else { files.push(file_info); }                       // is file
}
children.close(null, null);
>>>>

If there's a file or directory in "path" with restrictive permissions, then line 2 (folder.enumerate_children) throws this error:

(gnome-shell:31408): Gjs-WARNING **: JS ERROR: Gio.IOErrorEnum: Permission denied

and execution stops there.

I can't encapsulate it in a try/catch since I then can't iterate over the rest of the content in "path".

How can I ignore such files/folders in folder.enumerate_children?

I'm not sure, but try fetching only the attributes you need, instead of '*'. It might be stopping because the full list of attributes includes one that you need permissions to fetch.

Regards,
Philip


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]