Skip to content

Commit edec71c

Browse files
committed
Use filepath.Clean to remove trailing slashes
Signed-off-by: Darren Stahl <[email protected]>
1 parent f216d8a commit edec71c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mount/mount_windows.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ func (m *Mount) Mount(target string) (retErr error) {
9898
}
9999
}
100100

101-
for strings.HasSuffix(target, string(os.PathSeparator)) {
102-
target = target[:len(target)-1]
103-
}
104-
105-
idf, err := os.Create(target + ":layerid")
101+
// Remove any trailing slashes in preparation to add an Alternate Data Stream for the layerid,
102+
// see https://blogs.technet.microsoft.com/askcore/2013/03/24/alternate-data-streams-in-ntfs/
103+
// for details on Alternate Data Streams.
104+
target = filepath.Clean(target)
105+
dir, file := filepath.Split(target)
106+
idf, err := os.Create(filepath.Join(dir, file+":layerid"))
106107
if err != nil {
107108
return err
108109
}
@@ -140,7 +141,10 @@ func Unmount(mount string, flags int) error {
140141
return errors.Wrapf(err, "unable to find mounted volume %s", mount)
141142
}
142143

143-
layerPathb, err := ioutil.ReadFile(mount + ":layerid")
144+
// Remove any trailing slashes
145+
mount = filepath.Clean(mount)
146+
dir, file := filepath.Split(mount)
147+
layerPathb, err := ioutil.ReadFile(filepath.Join(dir, file+":layerid"))
144148
if err != nil {
145149
return err
146150
}

0 commit comments

Comments
 (0)