mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 05:33:49 +03:00
browse: Exclude symlink target size from total, show arrow on size (#6412)
* fileserver: Exclude symlink target size from total, show arrow on size * Keep both totals * Linter doesn't like my spelling :( * Stop parallelizing tests for now * Update modules/caddyhttp/fileserver/browse.html * Minor renamings --------- Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
88c7e53da5
commit
9338741ca7
3 changed files with 24 additions and 4 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -157,7 +157,7 @@ jobs:
|
|||
|
||||
# The environment is fresh, so there's no point in keeping accepting and adding the key.
|
||||
rsync -arz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress --delete --exclude '.git' . "$CI_USER"@ci-s390x.caddyserver.com:/var/tmp/"$short_sha"
|
||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -t "$CI_USER"@ci-s390x.caddyserver.com "cd /var/tmp/$short_sha; go version; go env; printf "\n\n";CGO_ENABLED=0 go test -tags nobadger -v ./..."
|
||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -t "$CI_USER"@ci-s390x.caddyserver.com "cd /var/tmp/$short_sha; go version; go env; printf "\n\n";CGO_ENABLED=0 go test -p 1 -tags nobadger -v ./..."
|
||||
test_result=$?
|
||||
|
||||
# There's no need leaving the files around
|
||||
|
|
|
@ -991,7 +991,7 @@ footer {
|
|||
<div class="sizebar">
|
||||
<div class="sizebar-bar"></div>
|
||||
<div class="sizebar-text">
|
||||
{{.HumanSize}}
|
||||
{{if .IsSymlink}}↱ {{end}}{{.HumanSize}}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -80,6 +80,13 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
|
|||
}
|
||||
|
||||
size := info.Size()
|
||||
|
||||
if !isDir {
|
||||
// increase the total by the symlink's size, not the target's size,
|
||||
// by incrementing before we follow the symlink
|
||||
tplCtx.TotalFileSize += size
|
||||
}
|
||||
|
||||
fileIsSymlink := isSymlink(info)
|
||||
symlinkPath := ""
|
||||
if fileIsSymlink {
|
||||
|
@ -103,7 +110,8 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
|
|||
}
|
||||
|
||||
if !isDir {
|
||||
tplCtx.TotalFileSize += size
|
||||
// increase the total including the symlink target's size
|
||||
tplCtx.TotalFileSizeFollowingSymlinks += size
|
||||
}
|
||||
|
||||
u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
|
||||
|
@ -150,9 +158,15 @@ type browseTemplateContext struct {
|
|||
// The number of files (items that aren't directories) in the listing.
|
||||
NumFiles int `json:"num_files"`
|
||||
|
||||
// The total size of all files in the listing.
|
||||
// The total size of all files in the listing. Only includes the
|
||||
// size of the files themselves, not the size of symlink targets
|
||||
// (i.e. the calculation of this value does not follow symlinks).
|
||||
TotalFileSize int64 `json:"total_file_size"`
|
||||
|
||||
// The total size of all files in the listing, including the
|
||||
// size of the files targeted by symlinks.
|
||||
TotalFileSizeFollowingSymlinks int64 `json:"total_file_size_following_symlinks"`
|
||||
|
||||
// Sort column used
|
||||
Sort string `json:"sort,omitempty"`
|
||||
|
||||
|
@ -288,6 +302,12 @@ func (btc browseTemplateContext) HumanTotalFileSize() string {
|
|||
return humanize.IBytes(uint64(btc.TotalFileSize))
|
||||
}
|
||||
|
||||
// HumanTotalFileSizeFollowingSymlinks is the same as HumanTotalFileSize
|
||||
// except the returned value reflects the size of symlink targets.
|
||||
func (btc browseTemplateContext) HumanTotalFileSizeFollowingSymlinks() string {
|
||||
return humanize.IBytes(uint64(btc.TotalFileSizeFollowingSymlinks))
|
||||
}
|
||||
|
||||
// HumanModTime returns the modified time of the file
|
||||
// as a human-readable string given by format.
|
||||
func (fi fileInfo) HumanModTime(format string) string {
|
||||
|
|
Loading…
Reference in a new issue