Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit f252baa

Browse files
authored
Merge pull request #59 merge from branch 26 - 4
2 parents f21ec51 + b3956a1 commit f252baa

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ services:
3636
# Mount the local './storage' directory into the container.
3737
# This makes it easy to see generated files on your host machine.
3838
- ./storage:/app/storage
39+
command: >
40+
sh -c "mkdir -p /app/storage && chown -R cnb:cnb /app/storage && java -jar /workspace/BOOT-INF/lib/spring-project-steganography-tool-v1.jar"
3941
networks:
4042
- stego-network
4143
depends_on:

src/main/java/com/example/springprojectsteganographytool/services/StorageService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import com.example.springprojectsteganographytool.exceptions.data.StorageSecurityException;
55
import org.springframework.core.io.Resource;
66

7-
import java.io.IOException;
87
import java.nio.file.Path;
98

109
public interface StorageService {
1110
Path save(String relativeFileName, byte[] content) throws
12-
StorageSecurityException, StorageException, IOException;
11+
StorageSecurityException, StorageException;
1312

1413
// Returns true if the file was deleted, false if the file did not exist
1514
boolean delete(String relativeFileName) throws StorageException;

src/main/java/com/example/springprojectsteganographytool/services/impl/StorageServiceImpl.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,22 @@ public StorageServiceImpl(@Value("${app.storage.base-path}") Path basePath) thro
4747
* @param relativeFileName the relative name of the file to save.
4848
* @param content the content of the file as a byte array.
4949
* @return the path to the saved file.
50-
* @throws StorageSecurityException if the file name is invalid or attempts to escape the storage directory.
50+
* @throws StorageSecurityException if an attempt is made to escape the storage directory.
5151
* @throws StorageException if an error occurs during file operations.
52-
* @throws IOException if an I/O error occurs.
5352
*/
5453
@Override
55-
public Path save(String relativeFileName, byte[] content) throws StorageSecurityException, StorageException, IOException {
54+
public Path save(String relativeFileName, byte[] content) throws StorageSecurityException, StorageException {
5655
log.debug("Saving file: {} ({} bytes)", relativeFileName, content.length);
5756

58-
var targetPath = safeResolve(relativeFileName);
59-
Files.createDirectories(targetPath.getParent());
60-
Files.write(targetPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
61-
log.debug("Saved file: {} ({} bytes)", targetPath, content.length);
62-
return targetPath;
57+
try {
58+
var targetPath = safeResolve(relativeFileName);
59+
Files.createDirectories(targetPath.getParent());
60+
Files.write(targetPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
61+
log.debug("Saved file: {} ({} bytes)", targetPath, content.length);
62+
return targetPath;
63+
} catch (IOException e) {
64+
throw new StorageException("Failed to store file " + relativeFileName, e);
65+
}
6366
}
6467

6568
/**

0 commit comments

Comments
 (0)