Comments (9)
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>
from caddy.
Oh that's a neat idea. I like that.
from caddy.
Thanks for the report; indeed, that is a bit confusing.
from caddy.
Hmm, but which size should be shown under size
for symlinks?
Currently, if the symlink target exists, the size of the target is shown and that size is considered for the total size in the header. If the symlink target does not exist, the size of the symlink itself is shown.
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 use_symlink_size
to enable the use of the symlink size instead of the symlink-target size:
browse [<template_file>] {
reveal_symlinks
use_symlink_size
}
from caddy.
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 use_symlink_size
, might I suggest a more general subdirective like follow_symlinks
? Because the ModTime could also be relevant here. (I am not sure that it necessarily requires reveal_symlinks
though.)
from caddy.
I think it makes sense for symbolic links to indicate the actual size of the file they point to, but in that case, it's necessary to somehow more clearly indicate that it is a symbolic link. My main point is to correctly calculate the total size; in my example, it shows 1.2GB even though it's actually half that. Unfortunately, I don't quite understand how this works "under the hood," but if I were to imagine, on a web page, I would add some attribute to symbolic links to understand that it is a symbolic link and not include it when calculating the total folder size.
![Screenshot 2024-06-20 at 02 09 42](https://private-user-images.githubusercontent.com/2268209/341205411-fc201206-8af3-4ff5-a2e6-351241bb257b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkzMzA3ODgsIm5iZiI6MTcxOTMzMDQ4OCwicGF0aCI6Ii8yMjY4MjA5LzM0MTIwNTQxMS1mYzIwMTIwNi04YWYzLTRmZjUtYTJlNi0zNTEyNDFiYjI1N2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjVUMTU0ODA4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2UxYzdmMjRmYWIxMzczM2M2YjEwNTFmYTc1ZWUwNDgwM2FkOWQyNTUzZGI1Y2E4OWQ1MTJlYTA3MGExNDA1MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.z_7-tFbSqs01_vbCigsS3dhSBRviUbyZf78XjGsFOzo)
from caddy.
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.
from caddy.
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.
from caddy.
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.
from caddy.
Related Issues (20)
- [file_server browse] Layout setting is not saved HOT 12
- vars not expanded in path directives HOT 6
- Global option acme_dns doesn't work with global option cert_issuer HOT 2
- proxy_protocol in the global settings does not work HOT 6
- file.* global replacements trailing newline interaction with secrets HOT 3
- Load balancer sticky cookie should have a Max-Age configuration HOT 4
- Add Placeholders for forward_proxy_url HOT 1
- [Question] Caddy on windows - dns for .local and .localdomain HOT 3
- Feature Request: Support for SSH Protocol Forwarding HOT 1
- consider allowing global configuration in imported files HOT 2
- `basic_auth` does not work with environment variable substitution HOT 5
- readiness probe HOT 3
- Question about punycode/internationalized domains HOT 3
- HelloGitHub Badge
- Reverse proxy startup health check behavior results in 503 errors HOT 5
- Active health check logs on every check instead of state change HOT 1
- How to build a custom image with PHP-FPM 7.2/7.3/7.4 HOT 1
- Documentation claims `basicauth` was renamed to `basic_auth` but this doesn’t work for me on 2.8.4 HOT 5
- Active websocket connections are still closed on config reload HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from caddy.