JFIF$        dd7 

Viewing File: /usr/share/doc/rsync/support/munge-symlinks

#!/usr/bin/env python3
# This script will either prefix all symlink values with the string
# "/rsyncd-munged/" or remove that prefix.

import os, sys, argparse

SYMLINK_PREFIX = '/rsyncd-munged/'
PREFIX_LEN = len(SYMLINK_PREFIX)

def main():
    for arg in args.names:
        if os.path.islink(arg):
            process_one_arg(arg)
        elif os.path.isdir(arg):
            for fn in find_symlinks(arg):
                process_one_arg(fn)
        else:
            print("Arg is not a symlink or a dir:", arg, file=sys.stderr)


def find_symlinks(path):
    for entry in os.scandir(path):
        if entry.is_symlink():
            yield entry.path
        elif entry.is_dir(follow_symlinks=False):
            yield from find_symlinks(entry.path)


def process_one_arg(fn):
    lnk = os.readlink(fn)
    if args.unmunge:
        if not lnk.startswith(SYMLINK_PREFIX):
            return
        lnk = lnk[PREFIX_LEN:]
        while args.all and lnk.startswith(SYMLINK_PREFIX):
            lnk = lnk[PREFIX_LEN:]
    else:
        if not args.all and lnk.startswith(SYMLINK_PREFIX):
            return
        lnk = SYMLINK_PREFIX + lnk

    try:
        os.unlink(fn)
    except OSError as e:
        print("Unable to unlink symlink:", str(e), file=sys.stderr)
        return
    try:
        os.symlink(lnk, fn)
    except OSError as e:
        print("Unable to recreate symlink", fn, '->', lnk + ':', str(e), file=sys.stderr)
        return
    print(fn, '->', lnk)


if __name__ == '__main__':
    our_desc = """\
Adds or removes the %s prefix to/from the start of each symlink's value.
When given the name of a directory, affects all the symlinks in that directory hierarchy.
""" % SYMLINK_PREFIX
    epilog = 'See the "munge symlinks" option in the rsyncd.conf manpage for more details.'
    parser = argparse.ArgumentParser(description=our_desc, epilog=epilog, add_help=False)
    uniq_group = parser.add_mutually_exclusive_group()
    uniq_group.add_argument('--munge', action='store_true', help="Add the prefix to symlinks (the default).")
    uniq_group.add_argument('--unmunge', action='store_true', help="Remove the prefix from symlinks.")
    parser.add_argument('--all', action='store_true', help="Always adds the prefix when munging (even if already munged) or removes multiple instances of the prefix when unmunging.")
    parser.add_argument('--help', '-h', action='help', help="Output this help message and exit.")
    parser.add_argument('names', metavar='NAME', nargs='+', help="One or more directories and/or symlinks to process.")
    args = parser.parse_args()
    main()

# vim: sw=4 et
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL8=;6c| !qfF3aů&~$l}'NWUs$Uk^SV:U# 6w++s&r+nڐ{@29 gL u"TÙM=6(^"7r}=6YݾlCuhquympǦ GjhsǜNlɻ}o7#S6aw4!OSrD57%|?x>L |/nD6?/8w#[)L7+6〼T ATg!%5MmZ/c-{1_Je"|^$'O&ޱմTrb$w)R$& N1EtdU3Uȉ1pM"N*(DNyd96.(jQ)X 5cQɎMyW?Q*!R>6=7)Xj5`J]e8%t!+'!1Q5 !1 AQaqё#2"0BRb?Gt^## .llQT $v,,m㵜5ubV =sY+@d{N!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