You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/11/12 10:00:35 UTC

[GitHub] [maven-resolver] slawekjaranowski commented on a diff in pull request #218: [MRESOLVER-290] Expand use of atomic file ops

slawekjaranowski commented on code in PR #218:
URL: https://github.com/apache/maven-resolver/pull/218#discussion_r1020740896


##########
maven-resolver-connector-basic/src/main/java/org/eclipse/aether/connector/basic/BasicRepositoryConnector.java:
##########
@@ -455,9 +456,7 @@ public boolean fetchChecksum( URI remote, File local )
         protected void runTask()
                 throws Exception
         {
-            fileProcessor.mkdirs( file.getParentFile() );

Review Comment:
   Looks like not used in production code `org.eclipse.aether.spi.io.FileProcessor#mkdirs`



##########
maven-resolver-connector-basic/src/main/java/org/eclipse/aether/connector/basic/BasicRepositoryConnector.java:
##########
@@ -489,7 +488,7 @@ protected void runTask()
                         }
                     }
                 }
-                fileProcessor.move( tmp, file );

Review Comment:
   Looks like not used anymore - `org.eclipse.aether.spi.io.FileProcessor#move`



##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java:
##########
@@ -75,144 +78,49 @@ public boolean mkdirs( File directory )
         }
         catch ( IOException e )
         {
-            return false;
+            throw new UncheckedIOException( e );
         }
 
         File parentDir = canonDir.getParentFile();
         return ( parentDir != null && ( mkdirs( parentDir ) || parentDir.exists() ) && canonDir.mkdir() );
     }
 
     public void write( File target, String data )
-        throws IOException
+            throws IOException
     {
-        mkdirs( target.getAbsoluteFile().getParentFile() );
-
-        OutputStream out = null;
-        try
-        {
-            out = new FileOutputStream( target );
-
-            if ( data != null )
-            {
-                out.write( data.getBytes( StandardCharsets.UTF_8 ) );
-            }
-
-            out.close();
-            out = null;
-        }
-        finally
-        {
-            try
-            {
-                if ( out != null )
-                {
-                    out.close();
-                }
-            }
-            catch ( final IOException e )
-            {
-                // Suppressed due to an exception already thrown in the try block.
-            }
-        }
+        FileUtils.writeFile( target.toPath(), p -> Files.write( p, data.getBytes( StandardCharsets.UTF_8 ) ) );

Review Comment:
   Why not use directly `FileUtils..`



-- 
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: issues-unsubscribe@maven.apache.org

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