Nice little directory browser :D
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix/Utils.FileSystemInfo.UnravelLink: loop if the target doesnt exist

+31 -29
+12 -10
Components/Pages/api/Files.razor
··· 163 163 164 164 [SetsRequiredMembers] 165 165 public FileRow(FileSystemInfo baseFsi, String currentPath) { 166 - bool isLink = baseFsi.Attributes.HasFlag(FileAttributes.ReparsePoint); 166 + FileSystemInfo? _fsi; 167 + bool _isBad = false; 167 168 168 - // Fsi = isLink ? baseFsi.ReadLink()! : baseFsi; 169 - Fsi = baseFsi.UnravelLink(); 169 + try { 170 + _fsi = baseFsi.UnravelLink(); 171 + } catch { 172 + _isBad = true; 173 + _fsi = baseFsi; 174 + } 175 + 176 + Fsi = _fsi; 170 177 IsFile = Fsi is FileInfo; 171 - IsBad = !Fsi.IsReadable(); 178 + IsBad = _isBad || !Fsi.IsReadable(); 172 179 TypeString = IsFile ? "file" : "directory"; 173 180 Icon = IsBad 174 - ? Utils.AbbrIcon($"Server does not have permission to read this {TypeString}", "⚠️") 181 + ? Utils.AbbrIcon($"Server cannot read this {TypeString}", "⚠️") 175 182 : Utils.GetIconForFileType(Fsi); 176 183 Name = baseFsi.Name; // specifically want whatever its called in the directory we're looking at 177 184 IsDotFile = Name.StartsWith('.'); ··· 182 189 ? null 183 190 : System.IO.Path.Join(currentPath, Name); 184 191 Trail = IsFile ? null : '/'; 185 - 186 - // if (isLink) { 187 - // Console.WriteLine($"name {Name} isfile {IsFile} size {Size}"); 188 - // } 189 192 } 190 - 191 193 } 192 194 }
+19 -19
Utils.cs
··· 331 331 // if not link, return self 332 332 // see https://github.com/PowerShell/PowerShell/issues/25724 333 333 public FileSystemInfo? ReadLink() { 334 - if (!fsi.Attributes.HasFlag(FileAttributes.ReparsePoint)) { 334 + if (!fsi.Attributes.HasFlag(FileAttributes.ReparsePoint)) 335 335 return null; 336 - } 337 336 338 - if (OperatingSystem.IsWindows()) { 337 + if (OperatingSystem.IsWindows()) 339 338 return fsi.ResolveLinkTarget(true); 340 - } 341 339 342 340 Process rp = new Process { 343 341 StartInfo = new ProcessStartInfo("realpath", ["-m", fsi.FullName]) { ··· 349 347 rp.Start(); 350 348 var real = rp.StandardOutput.ReadLine(); 351 349 rp.WaitForExit(); 352 - 353 - if (Directory.Exists(real)) { 350 + 351 + if (Directory.Exists(real)) 354 352 return new DirectoryInfo(real); 355 - } 356 - 357 - // the file at real might not actually exist, but we want to return it anyways 358 - return new FileInfo(real ?? ""); 353 + 354 + if (File.Exists(real)) 355 + return new FileInfo(real); 356 + 357 + throw new FileNotFoundException($"Link target for {fsi.FullName} -> {fsi.LinkTarget} not found."); 359 358 } 360 359 361 - // TODO: uhh this might loop if the target doesnt exist 362 360 public FileSystemInfo UnravelLink() { 363 - FileSystemInfo floor = fsi ?? throw new ArgumentNullException(nameof(fsi)); 361 + FileSystemInfo here = fsi ?? throw new ArgumentNullException(nameof(fsi)); 362 + FileSystemInfo? next; 363 + 364 + while (true) { 365 + // let the exception propagate 366 + next = here.ReadLink(); 367 + 368 + if (next == null) 369 + return here; 364 370 365 - while (true) { 366 - if (floor!.ReadLink() != null) { 367 - floor = floor!.ReadLink()!; 368 - } else { 369 - return floor; 370 - } 371 + here = next; 371 372 } 372 - 373 373 } 374 374 } 375 375