Skip to content

Commit bb8f173

Browse files
committed
fix: actually fix symlink size resolution
1 parent b244a9f commit bb8f173

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

caskethttp/browse/browse.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,20 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
316316
fileIsSymlink := isSymlink(f)
317317
size := f.Size()
318318
if fileIsSymlink {
319-
info, err := os.Stat(name)
320-
if err != nil {
321-
log.Printf("[ERROR] Could not stat symlink %s: %v", name, err)
322-
} else {
323-
size = info.Size()
319+
// Open the jailed symlink to determine its real size
320+
filePath := path.Join(urlPath, f.Name())
321+
file, err := config.Fs.Root.Open(filePath)
322+
if err == nil {
323+
stat, statErr := file.Stat()
324+
file.Close()
325+
if statErr == nil {
326+
size = stat.Size()
327+
}
324328
}
329+
// An error most likely means the symlink target doesn't exist,
330+
// which isn't entirely unusual and shouldn't fail the listing.
331+
// In this case, just use the size of the symlink itself, which
332+
// was already set above.
325333
}
326334

327335
u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name

0 commit comments

Comments
 (0)