Skip to content

Commit

Permalink
Add a mechanism to ignore links during compression
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Dec 20, 2023
1 parent 4b5744d commit c4cc87d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
20 changes: 14 additions & 6 deletions v2/app/BlockCompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type BlockCompressor struct {
checksum bool
skipBlocks bool
fileReorder bool
noDotFile bool
noDotFiles bool
noLinks bool
autoBlockSize bool
inputName string
outputName string
Expand Down Expand Up @@ -204,11 +205,18 @@ func NewBlockCompressor(argsMap map[string]any) (*BlockCompressor, error) {
this.fileReorder = true
}

if check, prst := argsMap["noDotFile"]; prst == true {
this.noDotFile = check.(bool)
delete(argsMap, "noDotFile")
if check, prst := argsMap["noDotFiles"]; prst == true {
this.noDotFiles = check.(bool)
delete(argsMap, "noDotFiles")
} else {
this.noDotFile = false
this.noDotFiles = false
}

if check, prst := argsMap["noLinks"]; prst == true {
this.noLinks = check.(bool)
delete(argsMap, "noLinks")
} else {
this.noLinks = false
}

this.verbosity = argsMap["verbose"].(uint)
Expand Down Expand Up @@ -325,7 +333,7 @@ func (this *BlockCompressor) Compress() (int, uint64) {
target = target[0 : len(target)-1]
}

files, err = createFileList(target, files, isRecursive, this.noDotFile)
files, err = createFileList(target, files, isRecursive, this.noLinks, this.noDotFiles)

if err != nil {
if ioerr, isIOErr := err.(kio.IOError); isIOErr == true {
Expand Down
2 changes: 1 addition & 1 deletion v2/app/BlockDecompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (this *BlockDecompressor) Decompress() (int, uint64) {
target = target[0 : len(target)-1]
}

files, err = createFileList(target, files, isRecursive, false)
files, err = createFileList(target, files, isRecursive, false, false)

if err != nil {
if ioerr, isIOErr := err.(kio.IOError); isIOErr == true {
Expand Down
58 changes: 41 additions & 17 deletions v2/app/Kanzi.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ func processCommandLine(args []string, argsMap map[string]any) int {
checksum := false
skip := false
fileReorder := true
noDotFile := false
noDotFiles := false
noLinks := false
from := -1
to := -1
inputName := ""
Expand Down Expand Up @@ -395,7 +396,23 @@ func processCommandLine(args []string, argsMap map[string]any) int {
continue
}

noDotFile = true
noDotFiles = true
continue
}

if arg == "--no-link" {
if ctx != -1 {
log.Println(fmt.Sprintf(warningNoValOpt, _CMD_LINE_ARGS[ctx]), verbose > 0)
}

ctx = -1

if mode != "c" {
log.Println(fmt.Sprintf(warningCompressOpt, arg), verbose > 0)
continue
}

noLinks = true
continue
}

Expand Down Expand Up @@ -788,8 +805,12 @@ func processCommandLine(args []string, argsMap map[string]any) int {
argsMap["fileReorder"] = false
}

if noDotFile == true {
argsMap["noDotFile"] = true
if noDotFiles == true {
argsMap["noDotFiles"] = true
}

if noLinks == true {
argsMap["noLinks"] = true
}

argsMap["jobs"] = uint(tasks)
Expand Down Expand Up @@ -983,18 +1004,17 @@ func (this FileCompare) Less(i, j int) bool {
return this.data[i].Size > this.data[j].Size
}

func createFileList(target string, fileList []FileData, isRecursive, ignoreDotFile bool) ([]FileData, error) {
func createFileList(target string, fileList []FileData, isRecursive, ignoreLinks, ignoreDotFiles bool) ([]FileData, error) {
fi, err := os.Stat(target)

if err != nil {
return fileList, err
}

if ignoreDotFile == true {
idx := strings.LastIndex(target, pathSeparator)
if ignoreDotFiles == true {
shortName := target

if idx > 0 {
if idx := strings.LastIndex(shortName, pathSeparator); idx > 0 {
shortName = shortName[idx+1:]
}

Expand All @@ -1003,7 +1023,7 @@ func createFileList(target string, fileList []FileData, isRecursive, ignoreDotFi
}
}

if fi.Mode().IsRegular() {
if fi.Mode().IsRegular() || ((ignoreLinks == false) && (fi.Mode()&fs.ModeSymlink != 0)) {
fileList = append(fileList, *NewFileData(target, fi.Size()))
return fileList, nil
}
Expand All @@ -1018,16 +1038,19 @@ func createFileList(target string, fileList []FileData, isRecursive, ignoreDotFi
return err
}

if ignoreDotFile == true {
if ignoreDotFiles == true {
shortName := path
idx := strings.Index(shortName, pathSeparator+".")

if idx > 0 {
if idx := strings.LastIndex(shortName, pathSeparator); idx > 0 {
shortName = shortName[idx+1:]
}

if len(shortName) > 0 && shortName[0] == '.' {
return nil
}
}

if fi.Mode().IsRegular() {
if fi.Mode().IsRegular() || ((ignoreLinks == false) && (fi.Mode()&fs.ModeSymlink != 0)) {
fileList = append(fileList, *NewFileData(path, fi.Size()))
}

Expand All @@ -1046,11 +1069,10 @@ func createFileList(target string, fileList []FileData, isRecursive, ignoreDotFi
break
}

if ignoreDotFile == true {
if ignoreDotFiles == true {
shortName := de.Name()
idx := strings.LastIndex(shortName, pathSeparator)

if idx > 0 {
if idx := strings.LastIndex(shortName, pathSeparator); idx > 0 {
shortName = shortName[idx+1:]
}

Expand All @@ -1059,7 +1081,9 @@ func createFileList(target string, fileList []FileData, isRecursive, ignoreDotFi
}
}

fileList = append(fileList, *NewFileData(target+de.Name(), fi.Size()))
if fi.Mode().IsRegular() || ((ignoreLinks == false) && (fi.Mode()&fs.ModeSymlink != 0)) {
fileList = append(fileList, *NewFileData(target+de.Name(), fi.Size()))
}
}
}
}
Expand Down

0 comments on commit c4cc87d

Please sign in to comment.