[disk][unix] Fix #555 Unescape escaped sequences in fstab path in disk.Usage

This commit is contained in:
Lomanic 2018-07-24 00:24:05 +02:00
parent 6ddbb8c5d8
commit 00bbeb757e
1 changed files with 11 additions and 1 deletions

View File

@ -4,6 +4,7 @@ package disk
import (
"context"
"strconv"
"golang.org/x/sys/unix"
)
@ -24,7 +25,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
bsize := stat.Bsize
ret := &UsageStat{
Path: path,
Path: unescapeFstab(path),
Fstype: getFsType(stat),
Total: (uint64(stat.Blocks) * uint64(bsize)),
Free: (uint64(stat.Bavail) * uint64(bsize)),
@ -54,3 +55,12 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
return ret, nil
}
// Unescape escaped octal chars (like space 040, ampersand 046 and backslash 134) to their real value in fstab fields issue#555
func unescapeFstab(path string) string {
escaped, err := strconv.Unquote(`"` + path + `"`)
if err != nil {
return path
}
return escaped
}