Skip to content

Commit

Permalink
Merge pull request #1088 from nanovms/1086-fix-mapdirs
Browse files Browse the repository at this point in the history
1086 Fix directory mapping
  • Loading branch information
arknable authored Jun 18, 2021
2 parents 75f4515 + 3e5bcb3 commit 23b37fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 2 additions & 0 deletions fs/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ func (m *Manifest) MkdirPath(path string) {
}

func mkDirPath(parent map[string]interface{}, path string) map[string]interface{} {
path = strings.TrimPrefix(path, "/")
path = strings.TrimSuffix(path, "/")
parts := strings.Split(path, "/")
for _, element := range parts {
parent = mkDir(parent, element)
Expand Down
22 changes: 9 additions & 13 deletions lepton/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ func BuildManifest(c *types.Config) (*fs.Manifest, error) {

func addMappedFiles(src string, dest string, workDir string, m *fs.Manifest) error {
dir, pattern := filepath.Split(src)
parentDir := filepath.Base(dir)
err := filepath.Walk(dir, func(hostpath string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -364,24 +363,21 @@ func addMappedFiles(src string, dest string, workDir string, m *fs.Manifest) err
hostdir, filename := filepath.Split(hostpath)
matched, _ := filepath.Match(pattern, filename)
if matched {
if info.IsDir() {
addedDir := parentDir
hostBase := filepath.Base(hostpath)
if hostBase != parentDir {
filepath.Join(parentDir, hostBase)
}
return m.AddDirectory(addedDir, workDir)
}

reldir, err := filepath.Rel(dir, hostdir)
if err != nil {
return err
}
vmpath := filepath.Join(dest, reldir, filename)
err = m.AddFile(vmpath, hostpath)
if err != nil {
return err

if info.IsDir() {
m.MkdirPath(vmpath)
return nil
}

if (info.Mode() & os.ModeSymlink) == os.ModeSymlink {
return m.AddLink(vmpath, hostpath)
}
return m.AddFile(vmpath, hostpath)
}
return nil
})
Expand Down

0 comments on commit 23b37fe

Please sign in to comment.