You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2022/03/14 04:04:54 UTC

[GitHub] [jena] Aklakan edited a comment on pull request #1225: Geosparql transformation options

Aklakan edited a comment on pull request #1225:
URL: https://github.com/apache/jena/pull/1225#issuecomment-1066316066


   @kinow Yes, silently using the temp directory would cause issues for us. With my comment I had a pattern like this in mind:
   
   What I meant with my comment is a pattern like this:
   ```java
       Path dataFile = Path.of(finalTarget);
       Path dataFileTmp = dataFile.resolveSibling(dataFile.getFileName() + ".tmp");
       Callable<?> creationAction = () -> {
               try (OutputStream out = Files.newOutputStream(dataFileTmp)) {
                   // Write the dataFileTmp file
                   out.flush();
               }
       };
       safeCreate(dataFile, dataFileTmp, creationAction());
   
       // This method is pretty generic
       public static void safeCreate(Path dataFile, Path dataFileTmp, Callable<?> action) throws IOException {
           if (!Files.exists(dataFile)) {
               Thread deleteAction = new Thread(() -> Files.deleteIfExists(x));
               Runtime.getRuntime().addShutdownHook(deleteTmpFile);
               if (Files.exists(dataFileTmp)) {
                   // Delete stale tmpFile or raise exception that it exists}
                   // If ProcessFileLock in dboe supported checking if it's owning process is still is alive
                   // we could even create a message such as
                   // Temp file is already locked by still alive process 1234
               try {
                   action.call();
                   try {
                       Files.move(dataFileTmp, dataFile, StandardCopyOption.ATOMIC_MOVE);
                   } catch (AtomicMoveNotSupportedException e) {
                       Files.move(dataFileTmp, dataFile);
                   }
               } finally {
                   deleteAction.run();
                   Runtime.getRuntime().removeShutdownHook(deleteTmpFile);
               }
           }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org