Skip to content

Commit

Permalink
gfpcopy: preserve the modification mtime of files over -T (default 1G…
Browse files Browse the repository at this point in the history
…iB).

(gfcp is used for such files)
  • Loading branch information
takuya-isbs committed Aug 11, 2024
1 parent bee656e commit 7c40ead
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
18 changes: 18 additions & 0 deletions gftool/gfprep/gfarm_pfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ pfunc_copy_by_gfcp(gfarm_pfunc_t *handle,
const char *src_url, char *src_host, gfarm_off_t src_size,
const char *dst_url, char *dst_host)
{
gfarm_error_t e;
struct pfunc_stat src_st;
int result = PFUNC_RESULT_OK, retv;
char *src_url_uc = (char *)src_url; /* UNCONST */
char *dst_url_uc = (char *)dst_url; /* UNCONST */
Expand Down Expand Up @@ -706,7 +708,23 @@ pfunc_copy_by_gfcp(gfarm_pfunc_t *handle,
fprintf(stderr, "ERROR: copy failed: gfcp(%s, %s)\n",
src_url, dst_url);
result = PFUNC_RESULT_NG;
goto end;
}
e = pfunc_lstat(src_url, &src_st);
if (e != GFARM_ERR_NO_ERROR) {
fprintf(stderr, "ERROR: copy failed: lstat(%s): %s\n",
src_url, gfarm_error_string(e));
result = PFUNC_RESULT_NG;
goto end;
}
e = pfunc_lutimens(dst_url, &src_st);
if (e != GFARM_ERR_NO_ERROR) {
fprintf(stderr, "ERROR: copy failed: utime(%s): %s\n",
dst_url, gfarm_error_string(e));
result = PFUNC_RESULT_NG;
goto end;
}
end:
return (result);
}

Expand Down
3 changes: 3 additions & 0 deletions regress/gftool/gfprep/gfpcopy_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ else
exit $exit_fail
fi
check_local_entries $local_dir1
compare_mtime gfarm:$gf_dir1/dir/1byte file:$local_dir1/dir/1byte

if $GFPCOPY $OPT file:$local_dir1 gfarm:$gf_dir2; then
:
Expand All @@ -74,6 +75,7 @@ else
exit $exit_fail
fi
check_local_entries $local_dir2
compare_mtime gfarm:$gf_dir2/dir/1byte file:$local_dir2/dir/1byte

if $GFPCOPY $OPT gfarm:$gf_dir2 file:$local_dir2; then
:
Expand All @@ -84,6 +86,7 @@ else
fi
BASENAME=`basename $gf_dir2`
check_local_entries $local_dir2/$BASENAME
compare_mtime gfarm:$gf_dir2/dir/1byte file:$local_dir2/$BASENAME/dir/1byte

clean_test
exit $exit_pass
10 changes: 7 additions & 3 deletions regress/gftool/gfprep/gfpcopy_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ fi
test_copy() {
SIZE=$1
filename=COPYFILE
OPT="-b 65536 -f -d ${ADD_OPT}"
OPT="-b 65536 -f ${ADD_OPT}"
lfile=$local_dir1/$filename
gfile=$gf_dir1/$filename
if dd if=/dev/urandom of=$lfile bs=$SIZE count=1 > /dev/null; then
lfile2=$local_dir2/$filename
if dd if=/dev/urandom of=$lfile bs=$SIZE count=1 2> /dev/null; then
:
else
echo dd failed
Expand All @@ -38,14 +39,17 @@ test_copy() {
clean_test
exit $exit_fail
fi
compare_mtime file:$lfile gfarm:$gfile

if $GFPCOPY $OPT gfarm:$gfile file:$local_dir2; then
:
else
echo gfpcopy failed [gfarm to local]
clean_test
exit $exit_fail
fi
if cmp $lfile $local_dir2/$filename; then
compare_mtime gfarm:$gfile file:$lfile2
if cmp $lfile $lfile2; then
:
else
echo copied data is different
Expand Down
22 changes: 22 additions & 0 deletions regress/gftool/gfprep/setup_gfprep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,25 @@ check_N() {
exit $exit_fail
fi
}

get_mtime() {
file="$1"
case $file in
gfarm:*)
gfstat "$file" | grep ^Modify | cut -d' ' -f 2,3
;;
file:*)
f=${file#file:}
stat "$f" | grep ^Modify | cut -d' ' -f 2,3
;;
esac
}

compare_mtime() {
m1=`get_mtime $1`
m2=`get_mtime $2`
if [ "$m1" != "$m2" ]; then
echo "compare_mtime: $m1 != $m2 ($1, $2)"
exit $exit_fail
fi
}

0 comments on commit 7c40ead

Please sign in to comment.