diff --git a/pom.xml b/pom.xml index 7b513ac..951c674 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.fross dirsize - 2.2.20 + 2.2.21 dirsize diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 63e435c..60bedbd 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: dirsize -version: '2.2.20' +version: '2.2.21' summary: The Command line Directory Reporting Tool description: | DirSize is a directory reporting tool. It recursively scans diff --git a/src/main/java/org/fross/dirsize/Export.java b/src/main/java/org/fross/dirsize/Export.java index b6eff10..6dfd7c5 100644 --- a/src/main/java/org/fross/dirsize/Export.java +++ b/src/main/java/org/fross/dirsize/Export.java @@ -118,6 +118,7 @@ public boolean writeToDisk() { /** * createNewFile(): Creates a new file (duh) + * * @return */ public boolean createNewFile() { @@ -135,7 +136,11 @@ public boolean createNewFile() { * @return */ public String getName() { - return exportFile.getName(); + try { + return exportFile.getName(); + } catch (NullPointerException ex) { + return ""; + } } } diff --git a/src/main/java/org/fross/dirsize/Main.java b/src/main/java/org/fross/dirsize/Main.java index fa540b3..fd56172 100644 --- a/src/main/java/org/fross/dirsize/Main.java +++ b/src/main/java/org/fross/dirsize/Main.java @@ -80,8 +80,9 @@ public static void main(String[] args) { char sortBy = 's'; // Default is sortBy size. 'f' and 'd' are also allowed boolean errorDisplayFlag = true; boolean reverseSort = false; + boolean exportFlag = false; int terminalWidth = 90; - Export exportFile= new Export(); + Export exportFile = new Export(); // Define the HashMaps for the scanning results. The directory name will be the key. HashMap mapSize = new HashMap(); @@ -142,6 +143,8 @@ public static void main(String[] args) { // Export to CSV File case 'x': + exportFlag = true; + try { exportFile.setExportFilename(optG.getOptarg()); if (exportFile.createNewFile() == false) { @@ -484,7 +487,7 @@ public static void main(String[] args) { // Update the export objects exportFile.addExportLine(displayName, mapSize.get(key), mapFiles.get(key)); - + } colorCounter++; } @@ -522,9 +525,11 @@ public static void main(String[] args) { } // Export the results to a CSV file if user requested an export - if (exportFile.writeToDisk() == false) { - Output.printColorln(Ansi.Color.RED, "Error exporting to file: " + exportFile.getName()); - } + if (exportFlag == true) { + if (exportFile.writeToDisk() == false) { + Output.printColorln(Ansi.Color.RED, "Error exporting to file: " + exportFile.getName()); + } + } }