Browse Source

Refactor MountPoint Setup function in volume.go

Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
Boaz Shuster 8 năm trước cách đây
mục cha
commit
fb8b27cd41
1 tập tin đã thay đổi với 11 bổ sung13 xóa
  1. 11 13
      volume/volume.go

+ 11 - 13
volume/volume.go

@@ -153,20 +153,18 @@ func (m *MountPoint) Cleanup() error {
 // before creating the source directory on the host.
 // before creating the source directory on the host.
 func (m *MountPoint) Setup(mountLabel string, rootIDs idtools.IDPair, checkFun func(m *MountPoint) error) (path string, err error) {
 func (m *MountPoint) Setup(mountLabel string, rootIDs idtools.IDPair, checkFun func(m *MountPoint) error) (path string, err error) {
 	defer func() {
 	defer func() {
-		if err == nil {
-			if label.RelabelNeeded(m.Mode) {
-				if err = label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode)); err != nil {
-					if err == syscall.ENOTSUP {
-						err = nil
-						return
-					}
-					path = ""
-					err = errors.Wrapf(err, "error setting label on mount source '%s'", m.Source)
-					return
-				}
-			}
+		if err != nil || !label.RelabelNeeded(m.Mode) {
+			return
+		}
+
+		err = label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode))
+		if err == syscall.ENOTSUP {
+			err = nil
+		}
+		if err != nil {
+			path = ""
+			err = errors.Wrapf(err, "error setting label on mount source '%s'", m.Source)
 		}
 		}
-		return
 	}()
 	}()
 
 
 	if m.Volume != nil {
 	if m.Volume != nil {