Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/caddyhttp/fileserver/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ <h1>
<div class="sizebar">
<div class="sizebar-bar"></div>
<div class="sizebar-text">
{{.HumanSize}}
{{if .IsSymlink}}↱ {{end}}{{.HumanSize}}
</div>
</div>
</td>
Expand Down
24 changes: 22 additions & 2 deletions modules/caddyhttp/fileserver/browsetplcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.TotalFileSizeWithSymlinks += size
}

u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
Expand Down Expand Up @@ -150,9 +158,14 @@ 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 the 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.
TotalFileSizeWithSymlinks int64 `json:"total_file_size_with_symlinks"`

// Sort column used
Sort string `json:"sort,omitempty"`

Expand Down Expand Up @@ -288,6 +301,13 @@ func (btc browseTemplateContext) HumanTotalFileSize() string {
return humanize.IBytes(uint64(btc.TotalFileSize))
}

// HumanTotalFileSizeWithSymlinks returns the total size of
// all files in the listing (including symlinks) as a human-readable
// string in IEC format (i.e. power of 2 or base 1024).
func (btc browseTemplateContext) HumanTotalFileSizeWithSymlinks() string {
return humanize.IBytes(uint64(btc.TotalFileSizeWithSymlinks))
}

// HumanModTime returns the modified time of the file
// as a human-readable string given by format.
func (fi fileInfo) HumanModTime(format string) string {
Expand Down