Class InaTapeHelper
java.lang.Object
fr.gouv.vitam.storage.cold.server.util.InaTapeHelper
Helper class for tape operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for actions that may throw checked exceptions. -
Constructor Summary
ConstructorsConstructorDescriptionInaTapeHelper(TapeCatalogRepository tapeCatalogRepository, TapeDriveRepository tapeDriveRepository, InaTapeProxyConfiguration configuration) -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceDrivePosition(int driveIndex) Increments the position of the specified tape drive by one file.static StringdriveIdByIndex(int driveIndex) getTapeCatalogModel(String tapeCode) Retrieves a tape catalog model by its tape code.getTapeDriveModel(int driveIndex) Retrieves a tape drive model by its index.sanityCheckPath(String inputPath) Validates, normalizes, and secures a file path to prevent security vulnerabilities (Path Traversal).voidtryWriteAndUpdateDatabase(long fileSize, int driveIndex, InaTapeHelper.ThrowingRunnable writeAction) Executes a write atomically: validates capacity, runs the provided write action, then increments tape size.
-
Constructor Details
-
InaTapeHelper
public InaTapeHelper(TapeCatalogRepository tapeCatalogRepository, TapeDriveRepository tapeDriveRepository, InaTapeProxyConfiguration configuration)
-
-
Method Details
-
driveIdByIndex
-
tryWriteAndUpdateDatabase
public void tryWriteAndUpdateDatabase(long fileSize, int driveIndex, InaTapeHelper.ThrowingRunnable writeAction) throws Exception Executes a write atomically: validates capacity, runs the provided write action, then increments tape size. The entire sequence is synchronized to prevent race conditions between concurrent writes and load/unload.- Throws:
Exception
-
advanceDrivePosition
Increments the position of the specified tape drive by one file.- Parameters:
driveIndex- the index of the tape drive to update- Throws:
InaTapeProxyException- if the drive model cannot be retrieved or saved
-
getTapeDriveModel
Retrieves a tape drive model by its index.- Parameters:
driveIndex- the drive index- Returns:
- the tape drive model
- Throws:
InaTapeProxyServerException- if the drive is not found
-
getTapeCatalogModel
Retrieves a tape catalog model by its tape code.- Parameters:
tapeCode- the tape code- Returns:
- the tape catalog model
- Throws:
InaTapeProxyServerException- if the tape is not found
-
sanityCheckPath
Validates, normalizes, and secures a file path to prevent security vulnerabilities (Path Traversal). Also ensures that the path points to a regular file and not a directory.- Parameters:
inputPath- The raw file path provided as input.- Returns:
- The secured, absolute, and normalized Path object.
- Throws:
InaTapeProxyBadRequestException- If the path is invalid, malicious, or does not correspond to a file.
-