Только в cpio-2.6/rmt: rmt Только в cpio-2.6/rmt: rmt.o Только в cpio-2.6/src: copyin.o Только в cpio-2.6/src: copyout.o diff -ur cpio-2.6.orig/src/copypass.c cpio-2.6/src/copypass.c --- cpio-2.6.orig/src/copypass.c 2006-10-01 00:14:55 +0400 +++ cpio-2.6/src/copypass.c 2006-10-01 00:18:13 +0400 @@ -29,6 +29,46 @@ #define lchown chown #endif +/* Copy file */ +int copy_file(const char *infile, const char *outfile) +{ + int ifd, ofd, len; + struct stat in_stat; + mode_t oldmode; + char buf[4096]; /* XXX make it lerger. */ + if ((ifd = open(infile, O_RDONLY)) < 0) { + return -1; + } + fstat(ifd, &in_stat); + oldmode = umask(0); + if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, 07777 & in_stat.st_mode )) < 0) { + close(ifd); + umask(oldmode); + return -1; + } + fchown(ofd, in_stat.st_uid, in_stat.st_gid); + umask(oldmode); + while ((len = read(ifd, buf, sizeof(buf)))) { + int res; + if (len < 0) { + break; + } + /* XXX handle partial writes */ + res = write(ofd, buf, len); + if (res != len) { + len = -1; /* error marker */ + break; + } + } + close(ifd); + close(ofd); + if (len < 0) { + unlink(outfile); + return -1; /* error */ + } + return 0; /* success */ +} + /* Copy files listed on the standard input into directory `directory_name'. If `link_flag', link instead of copying. */ @@ -455,6 +495,8 @@ link_to_name (char *link_name, char *link_target) { int res = link (link_target, link_name); + if (res < 0) + copy_file(link_target, link_name); if (res < 0 && create_dir_flag) { create_all_directories (link_name); @@ -470,6 +512,10 @@ { error (0, errno, _("cannot link %s to %s"), link_target, link_name); + res = copy_file(link_target, link_name); + if (res) + strerror("copy_file"); } return res; } +