ref: 9a638c7b37a153e7ca727f7f26c4ddb18c8710d5
parent: e3fbb4ca9cc4174e8a020b5354e5bfa77bb93d5f
author: Noam Preil <[email protected]>
date: Fri Nov 24 13:10:47 EST 2023
add dry-run mode
--- a/clone.c
+++ b/clone.c
@@ -44,6 +44,7 @@
int fileprocs = Nfileprocs;
int blkprocs = Nblkprocs;
int verbose = 0;
+int dummy = 0;
long salt;
Dir *skipdir;
@@ -222,6 +223,8 @@
Dir d;
if(verbose)
print("%s\n", dst);
+ if(dummy)
+ return 1;
if(!(sd->mode & 0400)){
error("can't clone directory: '%s' permission denied", src);
@@ -268,7 +271,7 @@
}
while((n = dirread(fd, &dirs)) > 0){
for(d = dirs; n; n--, d++){
- if(d->mode & DMDIR && same(skipdir, d))
+ if(d->mode & DMDIR && !dummy && same(skipdir, d))
continue;
sn = smprint("%s/%s", src, d->name);
@@ -444,7 +447,7 @@
error("can't read: %r");
sendul(f->errchan, ~0);
}
- if(n > 0 && pwrite(dfd, buf, n, b->offset) != n){
+ if(!dummy && n > 0 && pwrite(dfd, buf, n, b->offset) != n){
error("can't write: %r");
sendul(f->errchan, ~0);
}
@@ -481,10 +484,12 @@
dst = smprint("%s.clone.%ld", f->dst, salt);
if(verbose)
print("%s\n", f->dst);
- f->dfd = create(dst, OWRITE, f->mode);
- if(f->dfd < 0){
- error("can't create: %r");
- goto End;
+ if(!dummy){
+ f->dfd = create(dst, OWRITE, f->mode);
+ if(f->dfd < 0){
+ error("can't create: %r");
+ goto End;
+ }
}
if(clonefile(f) < 0){
if(remove(dst) < 0)
@@ -491,6 +496,8 @@
error("can't remove: %r");
goto End;
}
+ if(dummy)
+ goto End;
cloneattr(f->dfd, f);
if(notemp)
goto End;
@@ -504,7 +511,6 @@
error("dirfwstat: %r");
goto End;
}
-
End:
filefree(f);
free(dst);
@@ -523,6 +529,9 @@
ARGBEGIN{
case 'v':
verbose++;
+ break;
+ case 'd':
+ dummy++;
break;
case 'b':
blksz = strtol(EARGF(usage()), nil, 0);