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

Could not remove legal directory. Only on mac and linux? #328

Closed
1 of 3 tasks
Osiris-Team opened this issue May 20, 2023 · 9 comments
Closed
1 of 3 tasks

Could not remove legal directory. Only on mac and linux? #328

Osiris-Team opened this issue May 20, 2023 · 9 comments
Labels
bug Something isn't working fixed Issue fixed and release pending merged Changes merged into devel branch

Comments

@Osiris-Team
Copy link
Collaborator

Osiris-Team commented May 20, 2023

I'm submitting a…

  • bug report
  • feature request
  • other

Short description of the issue/suggestion:
When trying to package on mac: Caused by: java.io.IOException: Unable to delete directory /Users/runner/work/Desku-Gradle-Starter-App/Desku-Gradle-Starter-App/desktop/build/desktop/desktop.app/Contents/PlugIns/jre.jre/Contents/Home/legal. at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1127) at io.github.fvarrui.javapackager.utils.FileUtils.removeFolder(FileUtils.java:247) ... 121 more
Full build log: https://github.com/Osiris-Team/Desku-Gradle-Starter-App/actions/runs/5032033612/jobs/9025447503

When trying to package on linux/ubuntu: Caused by: java.io.IOException: Unable to delete directory /home/runner/work/Desku-Gradle-Starter-App/Desku-Gradle-Starter-App/desktop/build/desktop/jre/legal. at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1127) at io.github.fvarrui.javapackager.utils.FileUtils.removeFolder(FileUtils.java:247) ... 149 more.
Full build log: https://github.com/Osiris-Team/Desku-Gradle-Starter-App/actions/runs/5032033612/jobs/9025447469

It's a multi-module project: https://github.com/Osiris-Team/Desku-Gradle-Starter-App

Steps to reproduce the issue/enhancement:

release.yml contains the commands executed for each platform: https://github.com/Osiris-Team/Desku-Gradle-Starter-App/blob/master/.github/workflows/release.yml

Relevant build.gradle file: https://github.com/Osiris-Team/Desku-Gradle-Starter-App/blob/master/desktop/build.gradle
Note that on windows that build.gradle file works without issues.

@fvarrui fvarrui added the bug Something isn't working label May 25, 2023
@fvarrui
Copy link
Owner

fvarrui commented May 25, 2023

Hi @Osiris-Team!
Ok, the problem is here (line 247):

public static void removeFolder(File folder) throws Exception {
Logger.info("Removing folder [" + folder + "]");
try {
deleteDirectory(folder);
} catch (IOException e) {
throw new Exception("Could not remove folder " + folder, e);
}
}

I'm not really sure why org.apache.commons.io.FileUtils.deleteDirectory is failing, but it usually does when it hasn't permissions or any file is locked by another process.

Maybe we can try removing folders on Linux and Mac OS using the native command rm:

public static void removeFolder(File folder) throws Exception {
    Logger.info("Removing folder [" + folder + "]");		
    try {			
        if (Platform.windows.isCurrentPlatform())
            deleteDirectory(folder);
        else {
            CommandUtils.execute("rm", "-fr", folder);
        }
    } catch (IOException e) {
        throw new Exception("Could not remove folder " + folder, e);
    }
}

I'll apply this patch and publish a snapshot version ASAP so you can test it.

@Osiris-Team
Copy link
Collaborator Author

@fvarrui I think I had a similar issue in another project. What I did was to create a for loop that retries to delete the file like 1000 times or so and only then throw an exception. That worked since the files seemed to be locked only for a short time.

@fvarrui fvarrui added the working on Work in progress on this issue label May 25, 2023
@fvarrui
Copy link
Owner

fvarrui commented May 25, 2023

Work in progress in branch issue-328

@fvarrui
Copy link
Owner

fvarrui commented May 26, 2023

Changes published as snapshot version 1.7.3-20230525.235840-4.

Please, test it and give some feedback.

@fvarrui
Copy link
Owner

fvarrui commented May 26, 2023

@fvarrui I think I had a similar issue in another project. What I did was to create a for loop that retries to delete the file like 1000 times or so and only then throw an exception. That worked since the files seemed to be locked only for a short time.

If this patch doesn't work, I'll try your approach

@Osiris-Team
Copy link
Collaborator Author

@fvarrui fvarrui added fixed Issue fixed and release pending and removed working on Work in progress on this issue labels Jun 6, 2023
@fvarrui
Copy link
Owner

fvarrui commented Jun 6, 2023

I'm going to keep this issue open until this patch is released

@fvarrui fvarrui reopened this Jun 6, 2023
@fvarrui
Copy link
Owner

fvarrui commented Jun 6, 2023

Branch issue-328 merged into devel and removed, ready to be deployed.

@fvarrui fvarrui added the merged Changes merged into devel branch label Aug 11, 2023
@fvarrui
Copy link
Owner

fvarrui commented Aug 11, 2023

1.7.3 released to Maven Central

@fvarrui fvarrui closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Issue fixed and release pending merged Changes merged into devel branch
Projects
None yet
Development

No branches or pull requests

2 participants