Deleting Git Repo. Blocked by SymLinks
Michael

Michael @emgodev

Joined:
Dec 12, 2018

Deleting Git Repo. Blocked by SymLinks

Publish Date: Jan 27 '19
2 9

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?

Comments 9 total

  • Petry DeChamp Richardson
    Petry DeChamp RichardsonJan 27, 2019

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

    • Michael
      MichaelJan 27, 2019
      $ 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
      
      • Petry DeChamp Richardson
        Petry DeChamp RichardsonJan 27, 2019

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

        • Michael
          MichaelJan 28, 2019

          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.

  • Ben Sinclair
    Ben SinclairJan 27, 2019

    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.

    • Michael
      MichaelJan 27, 2019
      .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.

    • Marc Mercer
      Marc MercerJan 27, 2019

      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.

      • Ben Sinclair
        Ben SinclairJan 27, 2019

        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.

    • Michael
      MichaelJan 28, 2019

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

Add comment