Skip to content

Commit

Permalink
Link FileIO.isInTmpFolder()
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Feb 12, 2024
1 parent c138882 commit 0efbf33
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.core.function.UnsafeSupplier;
import org.fugerit.java.core.io.FileIO;
import org.fugerit.java.core.io.helper.HelperIOException;
import org.fugerit.java.doc.val.core.DocTypeValidationResult;

Expand All @@ -15,16 +16,9 @@
public class ValUtils {

private ValUtils() {}

public static boolean isInTmpFolder( File tempFile ) throws IOException {
File tempDir = new File( System.getProperty( "java.io.tmpdir" ) );
log.info( "file -> {} (tmpdir : {})", tempFile, tempDir );
return tempFile.getCanonicalPath().startsWith(tempDir.getCanonicalPath() );
}

public static Response doIfInTmpFolder(File tempFile, UnsafeSupplier<Response, Exception> fun ) throws IOException {
Response res = null;
if ( isInTmpFolder( tempFile ) ) {
if ( FileIO.isInTmpFolder( tempFile ) ) {
res = HelperIOException.get( fun::get );
} else {
// no access
Expand Down

0 comments on commit 0efbf33

Please sign in to comment.