[disk][unix] Fix #555 Unescape escaped sequences in fstab path in disk.Usage
This commit is contained in:
parent
6ddbb8c5d8
commit
00bbeb757e
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue