You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ability to detect symbolic links will help guard against circular references when recursively reading a directory. For example, the following function breaks when encountering a symlink that refers to its own parent:
/** * Print file tree to the console * @param {FileSystemHandle} handle */asyncfunctionprintFileTree(handle){switch(handle.kind){case"file": {console.log(handle.name);return;}case"directory": {console.group(handle.name);forawait(constchildHandleofhandle.values()){awaitprintFileTree(childHandle);}console.groupEnd();return;}}}
A potential solution is to add a boolean property to indicate that a handle was created from a symlink. For example:
forawait(const[name,handle]ofdirHandle){if(handle.fromSymlink){// if visited, continue}switch(handle.kind){case"file":
// do stuff with file...case"directory":
// do stuff with directory...}}
Alternatively, directory iterators can return objects similar to Dirents from Node.js, which we can use to create handles. For example:
forawait(constentryofdirHandle){if(entry.isFile()){consthandle=entry.handle();// do stuff with file handle...}if(entry.isDirectory()){consthandle=entry.handle();// do stuff with directory handle...}if(entry.isSymlink()){constlinkedHandle=entry.handle();// do stuff with linked file/directory, skip if visited}}
The text was updated successfully, but these errors were encountered:
Agreed. It's not just Node.JS: supporting seeing a POSIX dirent link type would be a major boon.
It would be great to consider what other types we might be able to support here too. Sockets, character devices, block devices, FIFO ought all seem near-at-hand, like something that could be supported by the API in general & identified in directory listing.
The ability to detect symbolic links will help guard against circular references when recursively reading a directory. For example, the following function breaks when encountering a symlink that refers to its own parent:
A potential solution is to add a boolean property to indicate that a handle was created from a symlink. For example:
Alternatively, directory iterators can return objects similar to Dirents from Node.js, which we can use to create handles. For example:
The text was updated successfully, but these errors were encountered: