Skip to content

Commit 3872fac

Browse files
authored
fix: don't mix up runtimedir and metadir (#44)
1 parent f4390cd commit 3872fac

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

pkg/molecule/molecule.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,31 @@ type Molecule struct {
2525
config MountOCIOpts
2626
}
2727

28-
func (m Molecule) MetadataPath() (string, error) {
28+
// MetadataDir: Return a metadir for this molecule.
29+
// Returns:
30+
//
31+
// the base runtime dir (e.g. /run/atomfs),
32+
// the full metadata path (e.g. /run/atomfs/meta/NSNAME/expanded-path)
33+
// error
34+
func (m Molecule) MetadataPath() (string, string, error) {
2935

3036
mountNSName, err := common.GetMountNSName()
3137
if err != nil {
32-
return "", err
38+
return "", "", err
3339
}
3440
absTarget, err := filepath.Abs(m.config.Target)
3541
if err != nil {
36-
return "", err
42+
return "", "", err
3743
}
38-
metadir := filepath.Join(common.RuntimeDir(m.config.MetadataDir), "meta", mountNSName, common.ReplacePathSeparators(absTarget))
39-
return metadir, nil
44+
runtimedir := common.RuntimeDir(m.config.MetadataDir)
45+
46+
metadir := filepath.Join(runtimedir, "meta", mountNSName, common.ReplacePathSeparators(absTarget))
47+
48+
return runtimedir, metadir, nil
4049
}
4150

4251
func (m Molecule) MountedAtomsPath(parts ...string) (string, error) {
43-
metapath, err := m.MetadataPath()
52+
_, metapath, err := m.MetadataPath()
4453
if err != nil {
4554
return "", err
4655
}
@@ -193,7 +202,7 @@ var OverlayMountOptions = "index=off,xino=on,userxattr"
193202
// Mount mounts an overlay at dest, with writeable overlay as per m.config
194203
func (m Molecule) Mount(dest string) error {
195204

196-
metadir, err := m.MetadataPath()
205+
_, metadir, err := m.MetadataPath()
197206
if err != nil {
198207
return errors.Wrapf(err, "can't find metadata path")
199208
}
@@ -318,7 +327,7 @@ func UmountWithMetadir(dest, metadirArg string) error {
318327
},
319328
}
320329

321-
metadir, err := mol.MetadataPath()
330+
runtimedir, metadir, err := mol.MetadataPath()
322331
if err != nil {
323332
return errors.WithStack(err)
324333
}
@@ -423,7 +432,7 @@ func UmountWithMetadir(dest, metadirArg string) error {
423432
if err != nil {
424433
return err
425434
}
426-
destMetaDir := filepath.Join(common.RuntimeDir(metadir), "meta", mountNSName, common.ReplacePathSeparators(dest))
435+
destMetaDir := filepath.Join(common.RuntimeDir(runtimedir), "meta", mountNSName, common.ReplacePathSeparators(dest))
427436
if err := os.RemoveAll(destMetaDir); err != nil {
428437
return err
429438
}

0 commit comments

Comments
 (0)