Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Cannot delete a just cloned repository on Windows

Hi All,

I get an AccessDeniedException while trying to delete a repository (https://github.com/git/git.git) that was just clone. The Git instance is closed before attempting to delete it (see below). The problem is reproducible with the Git SCM repository itself (sorry, I couldn't find a smaller one) and HEAD from JGit on Windows.

Is this a bug in JGit or am I missing something?

Rüdiger

Test Case
---

public class DeleteRepositoryTest {

  @Rule
  public TemporaryFolder tempFolder = new TemporaryFolder();

  @Test
  public void testCloneAndDelete() throws Exception {
    File directory = tempFolder.newFolder( "repo" );
    Git git = Git.cloneRepository()
      .setURI( "https://github.com/git/git.git"; )
      .setDirectory( directory )
      .call();
    git.close();

    delete( directory );

    Assert.assertFalse( directory.exists() );
  }

  public static void delete( File file ) throws IOException {
    DeleteFileVisitor visitor = new DeleteFileVisitor();
    Files.walkFileTree( file.toPath(), visitor );
  }

  private static class DeleteFileVisitor extends SimpleFileVisitor<Path> {
    @Override
public FileVisitResult visitFile( Path path, BasicFileAttributes attributes )
      throws IOException
    {
      Files.deleteIfExists( path );
      return FileVisitResult.CONTINUE;
    }

    @Override
public FileVisitResult postVisitDirectory( Path directory, IOException exception )
      throws IOException
    {
      if( exception == null ) {
        Files.deleteIfExists( directory );
      } else {
        throw exception;
      }
      return FileVisitResult.CONTINUE;
    }
  }

}




Stacktrace
---

java.nio.file.AccessDeniedException: C:\...Temp\junit947403798057090778\repo\.git\objects\pack\pack-2aae225d2f5fadb0d2dd705ad6b965f188d0b86f.idx at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83) at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97) at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102) at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269) at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
    at java.nio.file.Files.deleteIfExists(Files.java:1165)
at com.codeaffine.jgit.example.DeleteRepositoryTest$DeleteFileVisitor.visitFile(DeleteRepositoryTest.java:48) at com.codeaffine.jgit.example.DeleteRepositoryTest$DeleteFileVisitor.visitFile(DeleteRepositoryTest.java:1)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
at com.codeaffine.jgit.example.DeleteRepositoryTest.delete(DeleteRepositoryTest.java:40) at com.codeaffine.jgit.example.DeleteRepositoryTest.testCloneAndDelete(DeleteRepositoryTest.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)




Back to the top