- if (access(pname(source), 2) < 0) {
- fprintf(stderr, "mv: no write access to %s\n", pname(source));
- return(1);
- }
- if (s1.st_dev != s2.st_dev) {
- fprintf(stderr, "mv: cannot move directories across devices\n");
- return(1);
- }
- if (s1.st_ino != s2.st_ino) {
- char dst[MAXN+5];
-
- if (chkdot(source) || chkdot(target)) {
- fprintf(stderr, "mv: Sorry, path names including %s aren't allowed\n", DOTDOT);
- return(1);
- }
- stat(source, &s1);
- if (check(pname(target), s1.st_ino))
- return(1);
- for (i = 1; i <= NSIG; i++)
- signal(i, SIG_IGN);
- if (link(source, target) < 0) {
- fprintf(stderr, "mv: cannot link %s to %s\n", target, source);
- return(1);
- }
- if (unlink(source) < 0) {
- fprintf(stderr, "mv: %s: cannot unlink\n", source);
- unlink(target);
- return(1);
- }
- strcat(dst, target);
- strcat(dst, "/");
- strcat(dst, DOTDOT);
- if (unlink(dst) < 0) {
- fprintf(stderr, "mv: %s: cannot unlink\n", dst);
- if (link(target, source) >= 0)
- unlink(target);
- return(1);
- }
- if (link(pname(target), dst) < 0) {
- fprintf(stderr, "mv: cannot link %s to %s\n",
- dst, pname(target));
- if (link(pname(source), dst) >= 0)
- if (link(target, source) >= 0)
- unlink(target);
- return(1);