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 fd5f650 commit bbd2527
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
11 changes: 7 additions & 4 deletions java/src/main/java/kanzi/app/BlockCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class BlockCompressor implements Runnable, Callable<Integer>
private final boolean checksum;
private final boolean skipBlocks;
private final boolean reoderFiles;
private final boolean noDotFile;
private final boolean noDotFiles;
private final boolean noLinks;
private final boolean autoBlockSize;
private final String inputName;
private final String outputName;
Expand Down Expand Up @@ -145,8 +146,10 @@ public BlockCompressor(Map<String, Object> map)
this.checksum = (bChecksum == null) ? false : bChecksum;
Boolean bReorder = (Boolean) map.remove("fileReorder");
this.reoderFiles = (bReorder == null) ? true : bReorder;
Boolean bNoDotFile = (Boolean) map.remove("noDotFile");
this.noDotFile = (bNoDotFile == null) ? false : bNoDotFile;
Boolean bNoDotFiles = (Boolean) map.remove("noDotFiles");
this.noDotFiles = (bNoDotFiles == null) ? false : bNoDotFiles;
Boolean bNoLinks = (Boolean) map.remove("noLinks");
this.noLinks = (bNoLinks == null) ? false : bNoLinks;
Boolean bAuto = (Boolean) map.remove("autoBlock");
this.autoBlockSize = (bAuto == null) ? false : bAuto;
this.verbosity = (Integer) map.remove("verbose");
Expand Down Expand Up @@ -208,7 +211,7 @@ public Integer call()
String target = isRecursive ? this.inputName :
this.inputName.substring(0, this.inputName.length()-1);

Kanzi.createFileList(target, files, isRecursive, this.noDotFile);
Kanzi.createFileList(target, files, isRecursive, this.noLinks, this.noDotFiles);
}
catch (IOException e)
{
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/kanzi/app/BlockDecompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Integer call()
String target = isRecursive ? this.inputName :
this.inputName.substring(0, this.inputName.length()-1);

Kanzi.createFileList(target, files, isRecursive, false);
Kanzi.createFileList(target, files, isRecursive, false, false);
}
catch (IOException e)
{
Expand Down
40 changes: 32 additions & 8 deletions java/src/main/java/kanzi/app/Kanzi.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private static int processCommandLine(String args[], Map<String, Object> map)
boolean checksum = false;
boolean skip = false;
boolean fileReorder = true;
boolean noDotFile = false;
boolean noDotFiles = false;
boolean noLinks = false;
boolean autoBlockSize = false;
String inputName = "";
String outputName = "";
Expand Down Expand Up @@ -333,7 +334,24 @@ else if ("STDOUT".equalsIgnoreCase(outputName))
continue;
}

noDotFile = true;
noDotFiles = true;
continue;
}

if (arg.equals("--no-link"))
{
if (ctx != -1)
printOut("Warning: ignoring option [" + CMD_LINE_ARGS[ctx] + "] with no value.", verbose>0);

ctx = -1;

if (mode != 'c')
{
printOut("Warning: ignoring option [" + arg + "]. Only applicable in compress mode.", verbose>0);
continue;
}

noLinks = true;
continue;
}

Expand Down Expand Up @@ -663,8 +681,11 @@ else if ("STDOUT".equalsIgnoreCase(outputName))
if (fileReorder == false)
map.put("fileReorder", false);

if (noDotFile == true)
map.put("noDotFile", true);
if (noDotFiles == true)
map.put("noDotFiles", true);

if (noLinks == true)
map.put("noLinks", true);

if (skip == true)
map.put("skipBlocks", true);
Expand Down Expand Up @@ -805,7 +826,7 @@ private static void printOut(String msg, boolean print)


public static void createFileList(String target, List<Path> files, boolean isRecursive,
boolean ignoreDotFiles) throws IOException
boolean ignoreLinks, boolean ignoreDotFiles) throws IOException
{
if (target == null)
return;
Expand All @@ -820,7 +841,9 @@ public static void createFileList(String target, List<Path> files, boolean isRec

if (Files.isRegularFile(root) == true)
{
files.add(root);
if ((ignoreLinks == false) ||(Files.isSymbolicLink(root) == false))
files.add(root);

return;
}

Expand Down Expand Up @@ -865,11 +888,12 @@ public static void createFileList(String target, List<Path> files, boolean isRec
}
}

files.add(entry);
if ((ignoreLinks == false) ||(Files.isSymbolicLink(entry) == false))
files.add(entry);
}
else if ((isRecursive == true) && (Files.isDirectory(entry) == true))
{
createFileList(entry.toString(), files, isRecursive, ignoreDotFiles);
createFileList(entry.toString(), files, isRecursive, ignoreLinks, ignoreDotFiles);
}
}
}
Expand Down

0 comments on commit bbd2527

Please sign in to comment.