@@ -126,6 +126,8 @@ private string GetEntryName(FileSystemInfo fileSystemInfo, out bool doesPreserve
126
126
Debug . Assert ( relativePath is not null ) ;
127
127
doesPreservePathStructure = true ;
128
128
entryName = relativePath ;
129
+
130
+ _cmdlet . WriteVerbose ( $ "Relative path, entry name: { entryName } ") ;
129
131
}
130
132
// Otherwise, return the name of the directory or file
131
133
else
@@ -137,6 +139,8 @@ private string GetEntryName(FileSystemInfo fileSystemInfo, out bool doesPreserve
137
139
{
138
140
entryName += System . IO . Path . DirectorySeparatorChar ;
139
141
}
142
+
143
+
140
144
return entryName ;
141
145
}
142
146
@@ -198,7 +202,14 @@ private static string GetPrefixForPath(System.IO.DirectoryInfo directoryInfo)
198
202
/// <returns></returns>
199
203
private bool TryGetPathRelativeToCurrentWorkingDirectory ( string path , out string ? relativePathToWorkingDirectory )
200
204
{
201
- string relativePath = System . IO . Path . GetRelativePath ( _cmdlet . SessionState . Path . CurrentFileSystemLocation . Path , path ) ;
205
+ Debug . Assert ( ! string . IsNullOrEmpty ( path ) ) ;
206
+ string ? workingDirectoryRoot = Path . GetPathRoot ( _cmdlet . SessionState . Path . CurrentFileSystemLocation . Path ) ;
207
+ string ? pathRoot = Path . GetPathRoot ( path ) ;
208
+ if ( workingDirectoryRoot != pathRoot ) {
209
+ relativePathToWorkingDirectory = null ;
210
+ return false ;
211
+ }
212
+ string relativePath = Path . GetRelativePath ( _cmdlet . SessionState . Path . CurrentFileSystemLocation . Path , path ) ;
202
213
relativePathToWorkingDirectory = relativePath . Contains ( ".." ) ? null : relativePath ;
203
214
return relativePathToWorkingDirectory is not null ;
204
215
}
0 commit comments