shadow subfolders

This commit is contained in:
2025-08-29 17:28:00 -06:00
parent 6dfe1f024c
commit c4cf0f7f93
2 changed files with 89 additions and 1 deletions

View File

@@ -958,3 +958,77 @@ If it still shows “Starting”, copy the latest lines from the console output
---
_**User**_
right now, it's dumping them into a soup in the shadow dir. instead, for every project, let's dump them into a separate folder within the shadow dir, named after the project.
---
_**Assistant**_
<think><details><summary>Thought Process</summary>**Considering sanitization for file paths**
I need to implement a sanitize function to handle illegal characters in the Windows file system. Since theres no existing function, I can either write a simple local method or create a helper in Utils. To keep things clean, I could in-line the logic in `Client.prepareWorkingDirectory` or create a new function called `sanitizePathComponent`. Adding a small private method inside Client might be a good option, even though its a large class. I can replace illegal characters like `[\\\\/:*?"<>|]` with underscores. Also, I need to ensure the subdirectory exists.
**Managing directory creation in UnzipUtils**
UnzipUtils is set to create directories as needed when writing the `mirrorFile` path, but the project root directory might not exist yet. Although MkDir operations will create parent directories, we still need to ensure the root exists if top-level entries are files—which is rare. When we encounter a directory entry in UnzipUtils, we submit MkDir for both `outFile` and `mirrorFile`. Creating the root directory isn't strictly necessary, but its acceptable to do so. Ill implement a sanitize function and adjust naming to reflect the project, ensuring illegal characters are replaced. I'll also modify `Client.java` where `mirrorDir` is referenced.
**Implementing folder name sanitization**
Im going to introduce a private static method in `Client` called `sanitizeForFolderName(String in)`, which will replace invalid characters with underscores and trim the input. Then, Ill construct `String projectMirrorDir = new File(mirrorDir, sanitizeForFolderName(ajob.getName())).getAbsolutePath();`. I need to pass this new `projectMirrorDir` to `Utils.unzipChunksIntoDirectoryWithMirror`.
Theres a potential issue if two projects have the same name, as it could overwrite the previously extracted one. However, since the user wants it named after the project, Ill keep that focus. Including a job ID could help avoid name collisions, but it wasn't requested. Still, I should notify the user that collisions can happen, while aiming for conciseness. After implementing the code change, Ill build it but skip the TODO list since this is just a simple edit.
**Applying patch and handling updates**
The developer's spec suggests using a todo tool for multi-step tasks, but since this is small, we can go ahead without one. We must include status updates in messages before tool calls, so Ill add those short updates. I'll apply the patch to `Client.java` and re-open the file to ensure consistent content, as weve made recent modifications.
I'll locate the section we previously changed to include the mirror logic and create a patch for that block. I also need to account for cases where `ajob.getName()` might be null. Although it should typically be set, its safer to handle nulls by defaulting to the string "project." Ill implement this patch and then run the `gradlew shadowJar` command before providing instructions. Let's proceed!</details></think>
---
I'll update the mirror extraction to place files under a subfolder named after the project, then rebuild.
---
---
---
---
```bash
./gradlew.bat shadowJar -x test
```
```
PS C:\Users\Nathan\Documents\client-nabber\client> ./gradlew.bat shadowJar -x test
> Task :compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 3s
3 actionable tasks: 3 executed
PS C:\Users\Nathan\Documents\client-nabber\client>
```
---
- Mirroring now writes into a subfolder per project: `-shadow-dir\<sanitized-project-name>\...`.
- I added a simple sanitizer to remove invalid path chars.
Use your same command; files should group per project automatically.
---

View File

@@ -974,10 +974,12 @@ import okhttp3.HttpUrl;
Instant startUnzip = Instant.now();
String mirrorDir = this.configuration.getShadowExtractDirectory();
if (mirrorDir != null && !mirrorDir.isEmpty() && ajob.getPassword() != null) {
String safeProjectName = sanitizeForFolderName(ajob.getName());
String projectMirrorDir = new File(mirrorDir, safeProjectName).getAbsolutePath();
ret = Utils.unzipChunksIntoDirectoryWithMirror(
ajob.getProjectDownload().getChunks().stream().map(chunk -> this.directoryManager.getCachePathFor(chunk)).collect(Collectors.toList()),
scenePath,
mirrorDir,
projectMirrorDir,
ajob.getPassword(),
log);
}
@@ -1003,6 +1005,18 @@ import okhttp3.HttpUrl;
return 0;
}
private static String sanitizeForFolderName(String name) {
if (name == null) {
return "project";
}
// Replace invalid Windows characters and trim
String sanitized = name.replaceAll("[\\\\/:*?\"<>|]", "_").trim();
if (sanitized.isEmpty()) {
return "project";
}
return sanitized;
}
@SuppressWarnings("unused") // Suppress false positive about this.isValidatingJob - PMD rule cannot detect time-sensitive reads
protected Error.Type confirmJob(Job ajob, int checkpoint) {
String urlReal = String.format(LOCALE, "%s&rendertime=%d&preptime=%d&memoryused=%s", ajob.getValidationUrl(), ajob.getRenderProcess().getRenderDuration(), ajob.getRenderProcess().getScenePrepDuration(),