Skip to content

pdist: Maintain symlink mtime #6

Merged
merged 3 commits into from
Dec 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions pdist/pdist
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ sub export_index
$type eq 'B' || $type eq 'C' ? $self->rdev :
'-'
),
$type eq 'F'||$type eq 'D' ? $self->mtime : '-',
$type eq 'F' || $type eq 'D' || $type eq 'L' ? $self->mtime : '-',
);
}

Expand All @@ -103,7 +103,7 @@ sub import_index
$F[3],$F[4], # uid,gid
($type eq 'B' || $type eq 'C' ? $F[5] : 0), # rdev
($type eq 'F' ? $F[5] : 0 ), # size
($type eq 'F'||$type eq 'D' ? $F[6] : 0 ), # mtime
($type eq 'F'|| $type eq 'D' || $type eq 'L' ? $F[6] : 0 ), # mtime
($type eq 'L' ? fn_unescape($F[5]) : ''), # target

],
Expand Down Expand Up @@ -306,7 +306,7 @@ sub index_file_sort { return sort @_; }

#---------------------------- lchown / mknod

our ($machine,$SYS_lchown,$SYS_mknod);
our ($machine,$SYS_lchown,$SYS_mknod,$lmtime_sub);
chomp($machine=`uname -m`);
if ($machine eq 'i686') {
$SYS_lchown=198; # __NR_lchown32 in /usr/include/asm/unistd.h
Expand All @@ -325,6 +325,24 @@ if ($machine eq 'i686') {
warn "unknown machine type $machine: named pipes,character and block devices can't be created\n";
}

if ($machine eq 'x86_64') {
our $SYS_utimensat=280; # /usr/include/asm/unistd_64.h
our $AT_FDCWD=-100; # /usr/include/fcntl.h
our $UTIME_OMIT=(1<<30)-2; # /usr/include/bits/stat.h
our $AT_SYMLINK_NOFOLLOW=0x100; # /usr/include/fcntl.h

$lmtime_sub=sub {
my ($path,$mtime)=@_;
my $tsa=pack 'qqqq',0,$UTIME_OMIT,$mtime,0;
syscall($SYS_utimensat,$AT_FDCWD,$path,$tsa,$AT_SYMLINK_NOFOLLOW) and die "$path: $!\n";
}
} else {
$lmtime_sub=sub {
my ($path,$mtime)=@_;
warn "$path: don't known how to change symlink mtime on target architecture\n";
}
}

sub lchown
{
my ($uid,$gid,$path)=@_;
Expand Down Expand Up @@ -453,6 +471,13 @@ sub fileop_ln_or_cp
}
}

sub fileop_lmtime {
my ($mtime,$path)=@_;
$fileop_debug and warn "lmtime $mtime $path\n";
$fileop_noop and return;
$lmtime_sub->($path,$mtime);
}

#--------------------------------------------

sub index_wanted
Expand Down Expand Up @@ -723,11 +748,16 @@ sub prog_update
$quiet or warn "ln -s ".$st_want->target." $filename\n";
fileop_symlink($st_want->target,$filename);
fileop_lchown($st_want->uid,$st_want->gid,$filename);
fileop_lmtime($st_want->mtime,$filename);
} else {
if ($st_is->uid != $st_want->uid || $st_is->gid != $st_want->gid) {
$quiet or warn "lchown ".$st_want->uid.':'.$st_want->gid." $filename\n";
fileop_lchown($st_want->uid,$st_want->gid,$filename);
}
if ($st_is->mtime != $st_want->mtime) {
$quiet or warn "set mtime of $filename\n";
fileop_lmtime($st_want->mtime,$filename);
}
}
} elsif ($st_want->type eq 'P') {
if (!$st_is || $st_is->type ne 'P') {
Expand Down