Skip to content

Commit

Permalink
Fixed directory mapping
Browse files Browse the repository at this point in the history
Added also symlink file handling
Trim separator prefix and suffix from passed path


Dirpath to be created should be using vmpath
  • Loading branch information
arknable committed Jun 18, 2021
1 parent 75f4515 commit 3e5bcb3
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 3e5bcb3

Please sign in to comment.