cp: add symlink deref flags -H and -L for cp and mv
This commit is contained in:
		
				
					committed by
					
						 sin
						sin
					
				
			
			
				
	
			
			
			
						parent
						
							360a63769c
						
					
				
				
					commit
					af8be7f92c
				
			
							
								
								
									
										10
									
								
								libutil/cp.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								libutil/cp.c
									
									
									
									
									
								
							| @@ -17,14 +17,14 @@ | ||||
|  | ||||
| int cp_aflag = 0; | ||||
| int cp_fflag = 0; | ||||
| int cp_Pflag = 0; | ||||
| int cp_pflag = 0; | ||||
| int cp_rflag = 0; | ||||
| int cp_vflag = 0; | ||||
| int cp_status = 0; | ||||
| char cp_HLPflag = 'L'; | ||||
|  | ||||
| int | ||||
| cp(const char *s1, const char *s2) | ||||
| cp(const char *s1, const char *s2, char ff) | ||||
| { | ||||
| 	FILE *f1, *f2; | ||||
| 	char *ns1, *ns2; | ||||
| @@ -39,9 +39,9 @@ cp(const char *s1, const char *s2) | ||||
| 	if (cp_vflag) | ||||
| 		printf("'%s' -> '%s'\n", s1, s2); | ||||
|  | ||||
| 	r = cp_Pflag ? lstat(s1, &st) : stat(s1, &st); | ||||
| 	r = ff == 'P' ? lstat(s1, &st) : stat(s1, &st); | ||||
| 	if (r < 0) { | ||||
| 		weprintf("%s %s:", cp_Pflag ? "lstat" : "stat", s1); | ||||
| 		weprintf("%s %s:", ff == 'P' ? "lstat" : "stat", s1); | ||||
| 		cp_status = 1; | ||||
| 		return 0; | ||||
| 	} | ||||
| @@ -83,7 +83,7 @@ cp(const char *s1, const char *s2) | ||||
| 					eprintf("%s/%s: filename too long\n", | ||||
| 						s2, d->d_name); | ||||
| 				} | ||||
| 				fnck(ns1, ns2, cp); | ||||
| 				fnck(ns1, ns2, cp, ff == 'H' ? 'P' : ff); | ||||
| 			} | ||||
| 		} | ||||
| 		closedir(dp); | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
| #include "../util.h" | ||||
|  | ||||
| void | ||||
| enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) | ||||
| enmasse(int argc, char *argv[], int (*fn)(const char *, const char *, char), char ff) | ||||
| { | ||||
| 	char *buf, *dir; | ||||
| 	int i, len; | ||||
| @@ -18,7 +18,7 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) | ||||
| 	size_t dlen; | ||||
|  | ||||
| 	if (argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) { | ||||
| 		fnck(argv[0], argv[1], fn); | ||||
| 		fnck(argv[0], argv[1], fn, ff); | ||||
| 		return; | ||||
| 	} else { | ||||
| 		dir = (argc == 1) ? "." : argv[--argc]; | ||||
| @@ -35,7 +35,7 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) | ||||
| 			eprintf("%s/%s: filename too long\n", dir, | ||||
| 			        basename(argv[i])); | ||||
| 		} | ||||
| 		fnck(argv[i], buf, fn); | ||||
| 		fnck(argv[i], buf, fn, ff); | ||||
| 	} | ||||
| 	free(buf); | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,8 @@ | ||||
| #include "../util.h" | ||||
|  | ||||
| void | ||||
| fnck(const char *a, const char *b, int (*fn)(const char *, const char *)) | ||||
| fnck(const char *a, const char *b, | ||||
|      int (*fn)(const char *, const char *, char), char ff) | ||||
| { | ||||
| 	struct stat sta, stb; | ||||
|  | ||||
| @@ -15,6 +16,6 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *)) | ||||
| 		eprintf("%s -> %s: same file\n", a, b); | ||||
| 	} | ||||
|  | ||||
| 	if (fn(a, b) < 0) | ||||
| 	if (fn(a, b, ff) < 0) | ||||
| 		eprintf("%s -> %s:", a, b); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user