Skip to content

Commit

Permalink
Corrected bug with an exception with export
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Jul 15, 2023
1 parent 171bf1d commit 2d5858c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.fross</groupId>
<artifactId>dirsize</artifactId>
<version>2.2.20</version>
<version>2.2.21</version>

<name>dirsize</name>

Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/fross/dirsize/Export.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public boolean writeToDisk() {

/**
* createNewFile(): Creates a new file (duh)
*
* @return
*/
public boolean createNewFile() {
Expand All @@ -135,7 +136,11 @@ public boolean createNewFile() {
* @return
*/
public String getName() {
return exportFile.getName();
try {
return exportFile.getName();
} catch (NullPointerException ex) {
return "";
}
}

}
15 changes: 10 additions & 5 deletions src/main/java/org/fross/dirsize/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Long> mapSize = new HashMap<String, Long>();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -484,7 +487,7 @@ public static void main(String[] args) {

// Update the export objects
exportFile.addExportLine(displayName, mapSize.get(key), mapFiles.get(key));

}
colorCounter++;
}
Expand Down Expand Up @@ -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());
}
}

}

Expand Down

0 comments on commit 2d5858c

Please sign in to comment.