Skip to content

Commit 23dc72b

Browse files
committed
cubap and Claude Sonnet team up for the win!
1 parent bbd02b8 commit 23dc72b

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

src/java/ImageUpload/UserImageCollection.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static void create(Connection conn, File zippedFile, User uploader, Manus
124124
throw new IOException("Cannot overwrite existing zip file: " + newZippedFile.getName());
125125
}
126126
} catch (IOException e) {
127-
if (e.getMessage().contains("Cannot overwrite")) {
127+
if (e.getMessage() != null && e.getMessage().contains("Cannot overwrite")) {
128128
throw e;
129129
}
130130
LOG.log(WARNING, "Unable to get canonical path for file comparison, proceeding with caution", e);
@@ -234,17 +234,17 @@ private static Stack merge(Stack a, Stack b) {
234234
* @throws IOException if the file doesnt exist..
235235
*/
236236
static public void extractFolder(String zipFile) throws ZipException, IOException {
237-
out.println(zipFile);
237+
LOG.log(INFO, "Extracting folder: {0}", zipFile);
238238
int BUFFER = 2048;
239239
File file = new File(zipFile);
240240

241-
ZipFile zip = new ZipFile(file);
242-
String newPath = zipFile.substring(0, zipFile.length() - 4);
243-
// scrub dirname
244-
newPath = newPath.trim().replaceAll("\\s|\\.", "_");
241+
try (ZipFile zip = new ZipFile(file)) {
242+
String newPath = zipFile.substring(0, zipFile.length() - 4);
243+
// scrub dirname
244+
newPath = newPath.trim().replaceAll("\\s|\\.", "_");
245245

246-
new File(newPath).mkdir();
247-
Enumeration zipFileEntries = zip.entries();
246+
new File(newPath).mkdir();
247+
Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();
248248

249249
// Process each entry
250250
while (zipFileEntries.hasMoreElements()) {
@@ -296,6 +296,10 @@ static public void extractFolder(String zipFile) throws ZipException, IOExceptio
296296
}
297297
}
298298
}
299+
} catch (IOException e) {
300+
LOG.log(SEVERE, "Failed to process zip file: " + zipFile, e);
301+
throw e;
302+
}
299303
}
300304

301305
/**
@@ -334,11 +338,11 @@ private static String sanitizeFilename(String filename) {
334338
for (int i = 0; i < pathParts.length; i++) {
335339
// Replace spaces, dots, and other problematic characters with dashes
336340
// Keep alphanumeric, hyphens, and underscores
337-
pathParts[i] = pathParts[i].trim()
338-
.replaceAll(SPACES_AND_DOTS_PATTERN.pattern(), "-")
339-
.replaceAll(SPECIAL_CHARS_PATTERN.pattern(), "-")
340-
.replaceAll(MULTIPLE_DASHES_PATTERN.pattern(), "-")
341-
.replaceAll(LEADING_TRAILING_DASHES_PATTERN.pattern(), "");
341+
String part = pathParts[i].trim();
342+
part = SPACES_AND_DOTS_PATTERN.matcher(part).replaceAll("-");
343+
part = SPECIAL_CHARS_PATTERN.matcher(part).replaceAll("-");
344+
part = MULTIPLE_DASHES_PATTERN.matcher(part).replaceAll("-");
345+
pathParts[i] = LEADING_TRAILING_DASHES_PATTERN.matcher(part).replaceAll("");
342346
}
343347

344348
// Rejoin path parts

0 commit comments

Comments
 (0)