Bug 498149 - Cannot delete .git/objects/pack/* files on Windows
Summary: Cannot delete .git/objects/pack/* files on Windows
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 10
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-19 11:10 EDT by Nobody - feel free to take it CLA
Modified: 2017-11-13 04:26 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nobody - feel free to take it CLA 2016-07-19 11:10:19 EDT
I am testing some plugins in Eclipse. Many tests clone a github repository. Before run of a test using same repository, I perform clean up of git folder by recursive removal of files programmatically. Unfortunately I was not able to delete it successfully because some PACK files in .git/objects/pack cannot be deleted. It is happening only on Windows. I found a thread on stackoverflow http://stackoverflow.com/questions/19191727/pack-file-from-git-repo-cant-be-deleted-using-file-delete-method which lead me to thread http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg01961.html. But even attempt to set packed Git MMAP to false has not solved the problem.
Comment 1 Christian Halstrick CLA 2016-07-20 04:44:15 EDT
Typically you have this problem if you don't close the repositories and the end of your test. This leads to the situation that JGit still has FileHandles open on packfiles and only on windows this leads to the situation that the packfiles can't be deleted.

I would concentrate on one of your tests which fails and make sure that the repos are closed. This became easier to achieve since Git classes became autocloseable. E.g. like in this class:

		try (Git git = Git.init().setDirectory(tmp.toFile()).call()) {
			System.out.println("Repo created in " + tmp);
			Files.write(tmp.resolve("a"), "a".getBytes());
			git.add().addFilepattern("a").call();
			git.commit().setMessage("add a").call();
		} finally {
			Files.walkFileTree(tmp, new SimpleFileVisitor<Path>() {
				public FileVisitResult visitFile(Path file,
						BasicFileAttributes attrs) throws IOException {
					Files.delete(file);
					return FileVisitResult.CONTINUE;
				}

				public FileVisitResult postVisitDirectory(Path dir,
						IOException exc) throws IOException {
					Files.delete(dir);
					return FileVisitResult.CONTINUE;
				}
			});
		}

(https://raw.githubusercontent.com/chalstrick/chrisFiles/master/git/java/src/Template_createRepoInTmp.java)