Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace os.Chdir logic in ISO9660 with absolute paths to allow for concurrent use #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace os.Chdir logic in ISO9660 with absolute paths to allow for co…
…ncurrent use
borisroman committed Mar 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 634685b52aa9f035e5ff5ae87991a2c592a35894
47 changes: 32 additions & 15 deletions filesystem/iso9660/finalize.go
Original file line number Diff line number Diff line change
@@ -400,7 +400,7 @@ func (fs *FileSystem) Finalize(options FinalizeOptions) error {
}

// starting point
root := dirList["."]
root := dirList["/"]
root.addProperties(1)

// if we need to relocate directories, must do them here, before finalizing order and sizes
@@ -811,36 +811,53 @@ func createPathTable(fi []*finalizeFileInfo) *pathTable {
}

func walkTree(workspace string) ([]*finalizeFileInfo, map[string]*finalizeFileInfo, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, nil, fmt.Errorf("could not get pwd: %v", err)
}
// make everything relative to the workspace
_ = os.Chdir(workspace)
dirList := make(map[string]*finalizeFileInfo)
fileList := make([]*finalizeFileInfo, 0)

var entry *finalizeFileInfo
err = filepath.Walk(".", func(fp string, fi os.FileInfo, err error) error {

err := filepath.Walk(workspace, func(fp string, fi os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("error walking path %s: %v", fp, err)
}
isRoot := fp == "."
name := fi.Name()
shortname, extension := calculateShortnameExtension(name)

isRoot := fp == workspace
var name, shortname, extension, parentDir string

if isRoot {
fp = "/"
name = string([]byte{0x00})
parentDir = fp
shortname = name
} else {
fp = strings.TrimPrefix(fp, workspace)
name = strings.TrimPrefix(fi.Name(), workspace)
parentDir, _ = filepath.Split(fp)
shortname, extension = calculateShortnameExtension(name)

if len(parentDir) > 1 {
parentDir = strings.TrimSuffix(parentDir, "/")
}
}

entry = &finalizeFileInfo{
isDir: fi.IsDir(),
isRoot: isRoot,
modTime: fi.ModTime(),
mode: fi.Mode(),
name: name,
path: fp,
shortname: shortname,
size: fi.Size(),
}
entry = &finalizeFileInfo{path: fp, name: name, isDir: fi.IsDir(), isRoot: isRoot, modTime: fi.ModTime(), mode: fi.Mode(), size: fi.Size(), shortname: shortname}

// we will have to save it as its parent
parentDir := filepath.Dir(fp)
parentDirInfo := dirList[parentDir]

if fi.IsDir() {
entry.children = make([]*finalizeFileInfo, 0, 20)
dirList[fp] = entry

if !isRoot {
parentDirInfo.children = append(parentDirInfo.children, entry)
dirList[parentDir] = parentDirInfo
@@ -853,13 +870,13 @@ func walkTree(workspace string) ([]*finalizeFileInfo, map[string]*finalizeFileIn
dirList[parentDir] = parentDirInfo
fileList = append(fileList, entry)
}

return nil
})
if err != nil {
return nil, nil, err
}
// reset the workspace
_ = os.Chdir(cwd)

return fileList, dirList, nil
}

2 changes: 1 addition & 1 deletion filesystem/iso9660/rockridge.go
Original file line number Diff line number Diff line change
@@ -184,7 +184,7 @@ func (r *rockRidgeExtension) UsePathtable() bool {
// Relocate restructure so that all directories are at a depth of 8 or fewer
func (r *rockRidgeExtension) Relocate(dirs map[string]*finalizeFileInfo) ([]*finalizeFileInfo, map[string]*finalizeFileInfo, error) {
files := make([]*finalizeFileInfo, 0)
root := dirs["."]
root := dirs["/"]
relocationDir := root
if relocationDir.depth == 8 {
return nil, nil, fmt.Errorf("cannot relocate when relocation parent already is max depth 8")