Skip to content

Commit

Permalink
Merge pull request #245 from diskfs/enable-parallel-iso9660-walk
Browse files Browse the repository at this point in the history
iso9660 and squashfs support for parallel writings
  • Loading branch information
deitch authored Aug 2, 2024
2 parents f92199d + e408c55 commit 5fa33cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
25 changes: 12 additions & 13 deletions filesystem/iso9660/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,27 +908,28 @@ 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)
var (
dirList = make(map[string]*finalizeFileInfo)
fileList = make([]*finalizeFileInfo, 0)
entry *finalizeFileInfo
serial uint64
)
err = filepath.Walk(".", func(fp string, fi os.FileInfo, err error) error {
err := filepath.WalkDir(workspace, func(actualPath string, d fs.DirEntry, err error) error {
if err != nil {
return fmt.Errorf("error walking path %s: %v", fp, err)
return fmt.Errorf("error walking path %s: %v", actualPath, err)
}
fp := strings.TrimPrefix(actualPath, workspace)
fp = strings.TrimPrefix(fp, string(filepath.Separator))
if fp == "" {
fp = "."
}
name := fi.Name()
name := d.Name()
_, extension := calculateShortnameExtension(name)

actualPath := path.Join(workspace, fp)

fi, err := d.Info()
if err != nil {
return fmt.Errorf("could not get file info for %s: %v", fp, err)
}
entry, err = finalizeFileInfoFromFile(fp, actualPath, fi)
if err != nil {
return err
Expand Down Expand Up @@ -960,8 +961,6 @@ func walkTree(workspace string) ([]*finalizeFileInfo, map[string]*finalizeFileIn
if err != nil {
return nil, nil, err
}
// reset the workspace
_ = os.Chdir(cwd)
return fileList, dirList, nil
}

Expand Down
27 changes: 16 additions & 11 deletions filesystem/squashfs/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"fmt"
"io"
iofs "io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -415,21 +416,24 @@ func finalizeFragment(buf []byte, to util.File, toOffset int64, c Compressor) (r
// because the inode data is different.
// The first entry in the return always will be the root
func walkTree(workspace string) ([]*finalizeFileInfo, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("could not get pwd: %v", err)
}
// make everything relative to the workspace
_ = os.Chdir(workspace)
dirMap := make(map[string]*finalizeFileInfo)
fileList := make([]*finalizeFileInfo, 0)
var entry *finalizeFileInfo
_ = filepath.Walk(".", func(fp string, fi os.FileInfo, err error) error {
err := filepath.WalkDir(workspace, func(actualPath string, d iofs.DirEntry, err error) error {
if err != nil {
return err
}
fp := strings.TrimPrefix(actualPath, workspace)
fp = strings.TrimPrefix(fp, string(filepath.Separator))
if fp == "" {
fp = "."
}
isRoot := fp == "."
name := fi.Name()
name := d.Name()
fi, err := d.Info()
if err != nil {
return fmt.Errorf("could not get file info for %s: %v", fp, err)
}
m := fi.Mode()
var fType fileType
switch {
Expand All @@ -448,7 +452,7 @@ func walkTree(workspace string) ([]*finalizeFileInfo, error) {
default:
fType = fileRegular
}
xattrNames, err := xattr.List(fp)
xattrNames, err := xattr.List(actualPath)
if err != nil {
return fmt.Errorf("unable to list xattrs for %s: %v", fp, err)
}
Expand Down Expand Up @@ -495,8 +499,9 @@ func walkTree(workspace string) ([]*finalizeFileInfo, error) {
fileList = append(fileList, entry)
return nil
})
// reset the workspace
_ = os.Chdir(cwd)
if err != nil {
return nil, err
}

return fileList, nil
}
Expand Down

0 comments on commit 5fa33cd

Please sign in to comment.