DEV Community

Cover image for Deleting Git Repo. Blocked by SymLinks
Michael
Michael

Posted on

Deleting Git Repo. Blocked by SymLinks

I am having some problems with symbolic link recursion. I have a git repo that refuses to leave my computer. I may never write immutable data again out of spite of this circumstance.

There does not seem to be many answers on this topic, or they're pertaining to people explicitly creating these symbolic links; what evil person would do this?

Any idea how to nuke a directory from virtual existence?

Top comments (9)

Collapse
 
moopet profile image
Ben Sinclair • Edited

Have you tried finding all the symlinks (try find .Trash-1003 -type l in the first instance) and deleting them individually?

I suspect that rm is following the links down to delete the nodes first, then backing up the tree. If a symlink is pointing to itself, its parent, or another symlink which is pointing, in turn, to one of those, then rm will recurse forever.

Running find without the -L option should mean it doesn't try to recurse within linked directories, so it shouldn't get the same problem as rm.

There're probably just one or two problem links and using rm on them one a time should work.

Collapse
 
emgodev profile image
Michael
.Trash-1003
.Trash-1003/files
.Trash-1003/files/.git
.Trash-1003/files/.git/objects
.Trash-1003/files/.git/objects/8f
.Trash-1003/files/.git/objects/8f/*
find: ‘.Trash-1003/files/.git/objects/8f/*/*’: Too many levels of symbolic links
.Trash-1003/files/.git/objects/8f/*/.. (
find: ‘.Trash-1003/files/.git/objects/8f/*/.. (/8f’: Too many levels of symbolic links
.Trash-1003/files/.git/objects/8f/.. (
find: ‘.Trash-1003/files/.git/objects/8f/.. (/8f’: Too many levels of symbolic links

It looks like it's the */ and (/, but deleting those just throws that same error.

Collapse
 
daemoen profile image
Marc Mercer

surprised you didn't suggest -exec rm -rf {} \; as an addon to the find....

Though, in the case of unusual issues, I tend to prefer going a bit deeper than most people, why not use the inode reference and delete it specifically by inode, though in this particular case, that should be drastically overkill.

rm -rf ./.git should be sufficient.

Collapse
 
moopet profile image
Ben Sinclair

I didn't suggest that because I don't see how it'd be any better than the original attempt - we've already established that rm -rf doesn't work if the directory contains some kind of self-reference. I'm not sure why the find came out with that output though, because it looks like it's reporting a lot of things that shouldn't be links.
I don't really know though, I'm just guessing.

Collapse
 
emgodev profile image
Michael

Your solution might've worked too, but I didn't test it when I moved it off the external usb.

Collapse
 
dechamp profile image
DeChamp

Did you try via terminal running ‘rm -r .git’?

Collapse
 
emgodev profile image
Michael • Edited
$ rm -r .Trash-1003
rm: cannot remove '.Trash-1003/files/.git/objects/8f/*/*': Too many levels of symbolic links
rm: cannot remove '.Trash-1003/files/.git/objects/8f/*/.. (/8f': Too many levels of symbolic links
rm: cannot remove '.Trash-1003/files/.git/objects/8f/*/.. (': Directory not empty
rm: cannot remove '.Trash-1003/files/.git/objects/8f/.. (/8f': Too many levels of symbolic links
rm: cannot remove '.Trash-1003/files/.git/objects/8f/.. (': Directory not empty
$ alias d
alias d='rm -vr --one-file-system --preserve-root '
$ alias noask
alias noask='-f '
$ d noask .Trash-1003/
rm: cannot remove '.Trash-1003/files/.git/objects/8f/*/*': Too many levels of symbolic links
rm: cannot remove '.Trash-1003/files/.git/objects/8f/*/.. (/8f': Too many levels of symbolic links
rm: cannot remove '.Trash-1003/files/.git/objects/8f/.. (/8f': Too many levels of symbolic links
Collapse
 
dechamp profile image
DeChamp

‘rm -rf .git’ will tell it to force delete the symlink and not follow.

Thread Thread
 
emgodev profile image
Michael

Worked, I had to move it off the external drive though. I had to not use my aliases though, which was weird. It would give the error when I tried to move it also.