X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=process;h=1d8e39d025aa6512d8d8e307f0dd946b3d7de471;hb=5bd2301f6cebf2feca65138977d766dd79d9a138;hp=bf3295ddfff085cd645aabd1510bb664df558bc3;hpb=2101c0a7fa5dbbc6df915feab299d5f1c2f5b124;p=ian-dotfiles.git diff --git a/process b/process index bf3295d..1d8e39d 100755 --- a/process +++ b/process @@ -32,7 +32,7 @@ sub read_prep ($) { if (!$c) { exec './gpt','config',$inputfile; die $!; } } sub fin_prep () { - $!=0; close P; die "$! $?" if $! or $?; + close P; die "$?" if $?; } read_prep('perms'); @@ -41,10 +41,24 @@ for (;;) { chomp; s/^\s+//; s/\s+$//; next if m/^\#/; next unless m/\S/; last if m/^\.$/; - m/^(.*\S)\s+([0-7]+)$/ or die; - ($of,$pe)=($1,oct $2); - $isdir= $of =~ s,/$,,; - ($isdir ? $dirperms{$of} : $fileperms{$of}) = $pe; + if (m/(.*\S)\s+\-\>\s+(\S.*)/) { + $linktargs{$1}= $2; + } elsif (m/^(.*\S)\s+\-\-$/) { + $exclude{$1}= 1; + } elsif (m/^(.*\S)\s+(\S+)$/) { + ($of,$pe)=($1,$2); + $isdir= $of =~ s,/$,,; + if ($pe =~ m/^[0-7]+$/) { + $pe= oct $&; + } elsif ($pe eq '+x') { + $pe= 0777&~$umask; + } elsif ($pe eq '/') { + $pe= 02777&~$umask; + } else { + die "$pe ?"; + } + ($isdir ? $dirperms{$of} : $fileperms{$of}) = $pe; + } } fin_prep(); @@ -100,6 +114,7 @@ sub prep_proc ($$) { opendir D, "files" or die $!; while ($if=readdir D) { next unless $if =~ m/^[_a-z0-9\\]/; + next if $if =~ m/\~$/; $of= $if; $of =~ s,_,/,g; $of =~ s,^/,,; @@ -108,6 +123,8 @@ while ($if=readdir D) { length $1 eq 1 ? $1 : sprintf '%c', hex $1 /ge; + next if $exclude{$of}; + mkparents($of); $newf= 'new/'.$if; prep_proc('files/'.$if,$newf); @@ -121,12 +138,11 @@ while ($if=readdir D) { if ($nowperms != $perms) { would($of, sprintf 'chmod %04o -> %04o', $nowperms, $perms); } - if (!$action) { - system 'diff','-u',$home.$of,$newf; - $?==0 or $?==256 or die $?; - $changes++ if $?; - } + system 'diff','-u',$home.$of,$newf; + $?==0 or $?==256 or die $?; + $changes++ if $?; } else { + die unless $!==&ENOENT; would($of, sprintf 'create %04o', $perms); } if ($action) { @@ -139,6 +155,25 @@ closedir D or die $!; die join(', ', keys %fileperms) if %fileperms; +foreach $link (keys %linktargs) { + mkparents($link); + $targ= $linktargs{$link}; + if (lstat $home.$link) { + -l _ or die "$link is not a link!"; + defined($rl= readlink $home.$link) or die $!; + } else { + die unless $!==&ENOENT; + $rl= undef; + } + if ($rl ne $targ) { + would($link, "symlink $targ <-"); + if ($action) { + unlink $home.$link if defined $rl; + symlink $targ,$home.$link or die $!; + } + } +} + foreach $dir (keys %dirperms) { ensuredir($dir); }