Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336800

Summary: Cannot delete a directory after cloning a repository into it
Product: [Technology] JGit Reporter: Tomasz Zarna <tomasz.zarna>
Component: JGitAssignee: Philipp Thun <philipp.thun>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: caniszczyk, stefan.lay
Version: 0.11   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 336227    
Attachments:
Description Flags
failing tests
none
failing test with org.eclipse.jgit.util.FileUtils
none
mylyn/context/zip none

Description Tomasz Zarna CLA 2011-02-10 06:58:53 EST
In bug 336227 I'm trying to be a good citizen and clean up after running tests. The problem I found is that I'm not able to delete directories with clones as long as tests are running. This boils down to a pack file that cannot be removed.

I've modified org.eclipse.jgit.api.CloneCommandTest to illustrate the issue I'm dealing with. I'm not sure if this is something I should upload to Gerrit. This is not a real patch.
Comment 1 Tomasz Zarna CLA 2011-02-10 06:59:37 EST
Created attachment 188677 [details]
failing tests
Comment 2 Chris Aniszczyk CLA 2011-02-10 09:57:10 EST
In JGit, we wrote a FileUtils class to help with this...

FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY);

org.eclipse.jgit.util.FileUtils

Try that first, if it doesn't work, then we can dig deeper.
Comment 3 Tomasz Zarna CLA 2011-02-10 10:48:34 EST
Created attachment 188693 [details]
failing test with org.eclipse.jgit.util.FileUtils

Thanks for the tip but it didn't help. I still get: "java.lang.AssertionError: Could not delete file C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\testCloneRepository3656357236185082524664761946001\.git\objects\pack\pack-5a1e97de671900849c0b7657ff9e866080544d28.pack [...]"
Comment 4 Tomasz Zarna CLA 2011-02-10 10:48:36 EST
Created attachment 188694 [details]
mylyn/context/zip
Comment 5 Philipp Thun CLA 2011-02-28 10:57:18 EST
You are creating a new Git object that has a repository associated with it. This repository is automatically opened and thus has to be closed so that file resources are released. By adding "git2.getRepository().close();" before "FileUtils.delete(...);", the repository gets closed, the pack file is released and removing the directory works.

I think contributing this enhanced test case would be a good idea.