Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUtils.foreceDelete consumed on Windows-System a lot of system resources #21

Open
muehlehh opened this issue Feb 19, 2017 · 4 comments

Comments

@muehlehh
Copy link

muehlehh commented Feb 19, 2017

The foreceDelete will consume on Windows system a lot of time, if it is called a lot of times for files which are not present on the file system.

The method did the following:
if ( !file.delete() ) {
if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) {
file = file.getCanonicalFile();
System.gc();
}
try {
Thread.sleep( 10 );
return file.delete();
} catch ( InterruptedException ignore ) {
return file.delete();
}
}

I suggest to have a look at the {{commons-io}} variant, which is much simpler and did not do any assumption on the opperation system.

A detailed blog entry can be found on my blog: https://kaffeeumeins.de/interesting-code-org-codehaus-plexus-util-fileutils-forcedeletefile

@khmarbaise
Copy link
Member

khmarbaise commented Feb 19, 2017

The why can be read in the javadoc of the method:

  /**
     * Accommodate Windows bug encountered in both Sun and IBM JDKs.
     * Others possible. If the delete does not work, call System.gc(),
     * wait a little and try again.
     *
     * @param file a file
     * @throws IOException if any
     */
    private static boolean deleteFile( File file )
        throws IOException

Furthermore you have analysed it so in deepth why not offering a patch and make it better ? Apart from that I have my doubts that this method is causing long running build in Eclipse cause it will not being called. The question is how you are doing full builds in Eclipse? Which Eclipse version do you use? Which Maven version do you use? and of course which M2E version do you use?

@michael-o
Copy link
Member

michael-o commented Feb 19, 2017

Is the bug still present these days?

@muehlehh
Copy link
Author

I saw that comment, but there are no references to have a look at :(

As describted in the blog it is in the yuicompressor-plugin which just want to be sure a file does not exists on the filesystem. If some other plugin will use this function in the same way it will also end up in consuming 100% CPU and slows down the build.
On the other hand, if the plugin does not correctly uses this function it should be fixed in the plugin and the documentation of forceDelete has to be changed.

@khmarbaise I just want to understand why it is programmed in this way, before changing it to use just file.delete (like commons-io, it looks like tjey have not those mentioned problems) -- changing without any question can produce a lot of trouble in the code which uses this function and in the community.

@michael-o: the code ist from the latest version 3.0.24

@michael-o
Copy link
Member

@muehlehh I was talking about:

Accommodate Windows bug encountered in both Sun and IBM JDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants