-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[file_server] Incorrect file size calculation #6409
Comments
Thanks for the report; indeed, that is a bit confusing. |
Hmm, but which size should be shown under I use a custom browse template, which does not reveal that a file is a symlink (that arrow), and therefore I prefer the size of the symlink target. If someone clicks on all files in the directory listing, the downloads combined will be the total size from the header because clicking on a symlink will download the target file. From that perspective, the size, and total size, makes sense. Furthermore, if a symlink has a known extension such as .gif, the symlink-arrow will not be shown in the icon and the user might not understand why the picture "sunset.png" only has 14 bytes. On the other hand, I understand the confusion. I would suggest a configurable option, such as browse [<template_file>] {
reveal_symlinks
use_symlink_size
} |
Yeah, good questions. I'm actually inclined to think that we should show the real size of the symlink rather than what it points to. As for |
I think it would be appropriate for a symbolic link to indicate its actual creation time, as well as the size of the file it points to (with an optional display of the actual size of the link itself, although I’m not sure if that’s generally useful to anyone). To avoid confusion, it is crucial to calculate the actual size of the directory. Example: if we have a directory with two files, one of which is file.img at 500MB and a symbolic link to it, the directory should be reported as 500MB, not 1GB as it currently is. |
I think we can just do this? diff --git a/modules/caddyhttp/fileserver/browsetplcontext.go b/modules/caddyhttp/fileserver/browsetplcontext.go
index 74c14608..47e3f146 100644
--- a/modules/caddyhttp/fileserver/browsetplcontext.go
+++ b/modules/caddyhttp/fileserver/browsetplcontext.go
@@ -80,6 +80,12 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
}
size := info.Size()
+
+ // increase the total by the symlink's size, not the target's size.
+ if !isDir {
+ tplCtx.TotalFileSize += size
+ }
+
fileIsSymlink := isSymlink(info)
symlinkPath := ""
if fileIsSymlink {
@@ -102,10 +108,6 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
// was already set above.
}
- if !isDir {
- tplCtx.TotalFileSize += size
- }
-
u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
tplCtx.Items = append(tplCtx.Items, fileInfo{ Moving the increment of the total to be earlier, before we follow the symlink. I don't think we need any config for this, seems obvious to me that the total should always just be the actual physical size of this directory and not include the amounts of linked files. |
Why should it show to visitor of a directory listing, that there are two files, both are reported with 500MB each, that the total size is not 1 GB, but 500MB. Another visitor might be confused that two files of 500MB each are just 500MB in total. Especially for users who don't care how the server operator have provided these files internally - some might not even know what a symbolic link is. I think that this coin has two sides. |
How's this? diff --git a/modules/caddyhttp/fileserver/browse.html b/modules/caddyhttp/fileserver/browse.html
index 7b0df1e5..6dece435 100644
--- a/modules/caddyhttp/fileserver/browse.html
+++ b/modules/caddyhttp/fileserver/browse.html
@@ -980,7 +980,7 @@ footer {
<div class="sizebar">
<div class="sizebar-bar"></div>
<div class="sizebar-text">
- {{.HumanSize}}
+ {{if .IsSymlink}}↱ {{end}}{{.HumanSize}}
</div>
</div>
</td> |
Oh that's a neat idea. I like that. |
hello!
I noticed incorrect file size calculation on the web page, and it would be cool if symbolic links could be seen more explicitly
My config:
Thank you!
The text was updated successfully, but these errors were encountered: