File tree Expand file tree Collapse file tree
src/client/pythonEnvironments/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,17 +106,26 @@ export async function resolveSymbolicLink(absPath: string): Promise<string> {
106106 return absPath ;
107107}
108108
109+ /**
110+ * Returns full path to sub directories of a given directory.
111+ * @param root
112+ * @param resolveSymlinks
113+ */
109114export async function * getSubDirs ( root : string , resolveSymlinks : boolean ) : AsyncIterableIterator < string > {
110- const dirContents = await fsapi . readdir ( root ) ;
115+ const dirContents = await fsapi . promises . readdir ( root , { withFileTypes : true } ) ;
111116 const generators = dirContents . map ( ( item ) => {
112117 async function * generator ( ) {
113- const fullPath = path . join ( root , item ) ;
114- const stat = await fsapi . lstat ( fullPath ) ;
115-
116- if ( stat . isDirectory ( ) ) {
118+ const fullPath = path . join ( root , item . name ) ;
119+ if ( item . isDirectory ( ) ) {
117120 yield fullPath ;
118- } else if ( resolveSymlinks && stat . isSymbolicLink ( ) ) {
119- yield await resolveSymbolicLink ( fullPath ) ;
121+ } else if ( resolveSymlinks && item . isSymbolicLink ( ) ) {
122+ // The current FS item is a symlink. It can potentially be a file
123+ // or a directory. Resolve it first and then check if it is a directory.
124+ const resolvedPath = await resolveSymbolicLink ( fullPath ) ;
125+ const resolvedPathStat = await fsapi . lstat ( resolvedPath ) ;
126+ if ( resolvedPathStat . isDirectory ( ) ) {
127+ yield resolvedPath ;
128+ }
120129 }
121130 }
122131
You can’t perform that action at this time.
0 commit comments