From 00bbeb757e18dfcae2d66962c94bb263c208d1c7 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Tue, 24 Jul 2018 00:24:05 +0200 Subject: [PATCH] [disk][unix] Fix #555 Unescape escaped sequences in fstab path in disk.Usage --- disk/disk_unix.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/disk/disk_unix.go b/disk/disk_unix.go index bafef51..c947848 100644 --- a/disk/disk_unix.go +++ b/disk/disk_unix.go @@ -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 +}