michael-o commented on a change in pull request #6:
URL: https://github.com/apache/maven-clean-plugin/pull/6#discussion_r771452564
##########
File path: src/main/java/org/apache/maven/plugins/clean/Cleaner.java
##########
@@ -115,9 +135,102 @@ public void delete( File basedir, Selector selector,
boolean followSymlinks, boo
File file = followSymlinks ? basedir : basedir.getCanonicalFile();
+ if ( selector == null && !followSymlinks && fastDir != null )
+ {
+ // If anything wrong happens, we'll just use the usual deletion
mechanism
+ if ( fastDelete( file ) )
+ {
+ return;
+ }
+ }
+
delete( file, "", selector, followSymlinks, failOnError, retryOnError
);
}
+ private boolean fastDelete( File baseDir )
+ {
+ // Handle the case where we use
${maven.multiModuleProjectDirectory}/target/.clean for example
+ if ( fastDir.getAbsolutePath().startsWith( baseDir.getAbsolutePath() )
)
+ {
+ try
+ {
+ File tmpDir = createTempDir( baseDir.getParentFile(),
baseDir.getName() + "." );
+ try
+ {
+ Files.move( baseDir.toPath(), tmpDir.toPath(),
StandardCopyOption.ATOMIC_MOVE );
+ if ( session != null )
+ {
+ session.getRequest().getData().put(
LAST_DIRECTORY_TO_DELETE, baseDir );
+ }
+ baseDir = tmpDir;
+ }
+ catch ( IOException e )
+ {
+ tmpDir.delete();
+ if ( logDebug != null )
+ {
+ logDebug.log( "Unable to fast delete directory: " + e
);
+ }
+ return false;
+ }
+ }
+ catch ( IOException e )
+ {
+ if ( logDebug != null )
+ {
+ logDebug.log( "Unable to fast delete directory: " + e );
+ }
+ return false;
+ }
+ }
+ // Create fastDir and the needed parents if needed
+ if ( fastDir.mkdirs() || fastDir.isDirectory() )
+ {
+ try
+ {
+ File tmpDir = createTempDir( fastDir, "" );
+ File dstDir = new File( tmpDir, baseDir.getName() );
+ // Note that by specifying the ATOMIC_MOVE, we expect an
exception to be thrown
+ // if the path leads to a directory on another mountpoint. If
this is the case
+ // or any other exception occurs, an exception will be thrown
in which case
+ // the method will return false and the usual deletion will be
performed.
+ Files.move( baseDir.toPath(), dstDir.toPath(),
StandardCopyOption.ATOMIC_MOVE );
+ BackgroundCleaner.delete( this, tmpDir );
+ return true;
+ }
+ catch ( IOException e )
+ {
+ if ( logDebug != null )
+ {
+ logDebug.log( "Unable to fast delete directory: " + e );
Review comment:
Shit, then please add a comment that this is intentional
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]