Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically delete .git .idx .pack files

Tags:

git

file

windows

ASP.NET C# app running on Windows Server 2008

I'm finding that Git .idx and .pack files to be especially resistant to programmatic deletion :

C:\github\my-org\my-repo\.git\objects\pack\pack-905fbcfd5f24c5711de900f3946b4137d26df6d5.idx

C:\github\my-org\my-repo\.git\objects\pack\pack-905fbcfd5f24c5711de900f3946b4137d26df6d5.pack

git clone operation creates files as read-only - but even once that bit switched-off, it remains problematic to delete :

var path = @"C:\github\my-org\my-repo\.git\objects\pack\pack-33ea2068b66028f98ac9deb55c3b5d1450d65dea.idx";

File.SetAttributes(path , FileAttributes.Normal);
File.Delete(path);

File.Delete(path) code throws exception :

Access to the path 'pack-33ea2068b66028f98ac9deb55c3b5d1450d65dea.idx' is denied.

Since the paths are not within my site dir, I'm wondering if the ASP.NET site AppPool worker-process identity needs to be explicitly assigned permissions to write/delete folders/files outside of its app domain ?

Note that on my Windows 7 local workstation, my nUnit test that invokes the delete dir operation runs green. In the debugger, I can prove that once the read-only attribute is removed from all files ( if present ), the Directory.Delete(path,true) operation does not throw.

like image 699
BaltoStar Avatar asked Jun 18 '15 02:06

BaltoStar


1 Answers

Either a process is keeping an handle on that specific pack file (process explorer can check that for you)

Or there is a right access issue, as in libgit2sharp/issues/769:

The message looks like the one you'd get when the reason is that you're trying to remove a read-only file, which Windows does not like, and the objects git's object database (of which that index file is one) are read-only.

Removing readonly flag allows me to delete the whole directory.

like image 103
VonC Avatar answered Oct 01 '22 04:10

VonC