Selaa lähdekoodia

daemon/graphdriver/zfs: use strings.Cut, and refactor

Fixes a (theoretical?) panic if ID would be shorter than 12
characters. Also trim the ID _after_ cutting off the suffix.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 vuotta sitten
vanhempi
commit
3f935d0e2c
1 muutettua tiedostoa jossa 9 lisäystä ja 11 poistoa
  1. 9 11
      daemon/graphdriver/zfs/zfs_freebsd.go

+ 9 - 11
daemon/graphdriver/zfs/zfs_freebsd.go

@@ -1,7 +1,6 @@
 package zfs // import "github.com/docker/docker/daemon/graphdriver/zfs"
 package zfs // import "github.com/docker/docker/daemon/graphdriver/zfs"
 
 
 import (
 import (
-	"fmt"
 	"strings"
 	"strings"
 
 
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver"
@@ -12,7 +11,7 @@ import (
 func checkRootdirFs(rootdir string) error {
 func checkRootdirFs(rootdir string) error {
 	var buf unix.Statfs_t
 	var buf unix.Statfs_t
 	if err := unix.Statfs(rootdir, &buf); err != nil {
 	if err := unix.Statfs(rootdir, &buf); err != nil {
-		return fmt.Errorf("Failed to access '%s': %s", rootdir, err)
+		return err
 	}
 	}
 
 
 	// on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ]
 	// on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ]
@@ -24,15 +23,14 @@ func checkRootdirFs(rootdir string) error {
 	return nil
 	return nil
 }
 }
 
 
-func getMountpoint(id string) string {
-	maxlen := 12
-
-	// we need to preserve filesystem suffix
-	suffix := strings.SplitN(id, "-", 2)
+const maxlen = 12
 
 
-	if len(suffix) > 1 {
-		return id[:maxlen] + "-" + suffix[1]
+func getMountpoint(id string) string {
+	id, suffix, _ := strings.Cut(id, "-")
+	id = id[:maxlen]
+	if suffix != "" {
+		// preserve filesystem suffix.
+		id += "-" + suffix
 	}
 	}
-
-	return id[:maxlen]
+	return id
 }
 }