comparison rvinterf/etmsync/cleandir.c @ 595:e6fe9d25377a

fc-fsio: rm-subtree command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 04 Feb 2020 05:30:59 +0000
parents 2c75cf810146
children
comparison
equal deleted inserted replaced
594:2c75cf810146 595:e6fe9d25377a
75 fprintf(stderr, "error: cleandir / is not allowed\n"); 75 fprintf(stderr, "error: cleandir / is not allowed\n");
76 return(ERROR_USAGE); 76 return(ERROR_USAGE);
77 } 77 }
78 return cleandir_level(argv[1]); 78 return cleandir_level(argv[1]);
79 } 79 }
80
81 cmd_rm_subtree(argc, argv)
82 char **argv;
83 {
84 char *pathname;
85 int rc, minusf_mode, found;
86 struct stat_info stat;
87
88 if (argc == 2) {
89 pathname = argv[1];
90 minusf_mode = 0;
91 } else {
92 if (strcmp(argv[1], "-f")) {
93 fprintf(stderr,
94 "usage: rm-subtree [-f] ffs_pathname\n");
95 return(ERROR_USAGE);
96 }
97 pathname = argv[2];
98 minusf_mode = 1;
99 }
100 rc = validate_ffs_pathname(pathname);
101 if (rc < 0)
102 return(ERROR_USAGE); /* err msg already printed */
103 if (rc == 0) {
104 fprintf(stderr, "error: rm-subtree / is not allowed\n");
105 return(ERROR_USAGE);
106 }
107 if (minusf_mode) {
108 rc = do_xlstat_notfoundok(pathname, &found, &stat);
109 if (rc)
110 return(rc);
111 if (!found)
112 return(0);
113 } else {
114 rc = do_xlstat(pathname, &stat);
115 if (rc)
116 return(rc);
117 }
118 if (stat.type != OT_DIR) {
119 printf("error: %s exists and is not a directory\n", pathname);
120 return(ERROR_TARGET);
121 }
122 rc = cleandir_level(pathname);
123 if (rc)
124 return(rc);
125 return do_ffs_remove(pathname, 0);
126 }