Fixing broken links

rikona rikona at sonic.net
Wed Feb 17 06:01:32 UTC 2016


Hello Ralf,

Tuesday, February 16, 2016, 7:02:01 PM, Ralf wrote:

> On Tue, 16 Feb 2016 14:16:35 -0800, rikona wrote:
>>Before I move/delete/rename a file/dir, is there a way to tell if that
>>will break links to that object?

> Without doing it recursively, it's already tricky,

I can reeeeally believe that. :-)

> since ...

> [rocketmouse at archlinux Desktop]$ ls -Gg *
> -rw-r--r-- 1  0 Feb 17 02:31 1
> lrwxrwxrwx 1  6 Feb 17 03:34 not_tricky -> tricky
> -rw-r--r-- 1  0 Feb 17 03:33 tricky
> -rw-r--r-- 1  0 Feb 17 03:36 tricky_2
> lrwxrwxrwx 1 10 Feb 17 03:49 very_tricky -> ./tricky_2
> [rocketmouse at archlinux Desktop]$ item_name=tricky_2
> [rocketmouse at archlinux Desktop]$ for l in $(find . -type l);do [[
> "$(readlink $l)" = "$item_name" ]] && echo -e "\n### ### ###  NOT OK ### ### ###\n";done
> [rocketmouse at archlinux Desktop]$ item_name=tricky
> [rocketmouse at archlinux Desktop]$ for l in $(find . -type l);do [[
> "$(readlink $l)" = "$item_name" ]] && echo -e "\n### ### ###  NOT OK ### ### ###\n";done

> ### ### ###  NOT OK  ### ### ###

> [rocketmouse at archlinux Desktop]$ item_name=1
> [rocketmouse at archlinux Desktop]$ for l in $(find . -type l);do [[
> "$(readlink $l)" = "$item_name" ]] && echo -e "\n### ### ###  NOT OK ### ### ###\n";done

> ... a link could be provided by different paths, so a script needs
> to "translate" it always to the full path.

Agreed - and there's always the chains of loops. Would it be best to
fix the simple ones to minimize the size of the 'output' list, then
brute force it from there? Could this result in some 'hidden' loops?

> False positives could be caused by links that link against paths that
> are only mounted on demand.

So far, I only have links to always mounted locations - I've tried to
avoid links to things that need mounting.

Is this really as hard as it sounds? :-((

-- 

 rikona        





More information about the ubuntu-users mailing list