MCPcopy Index your code
hub / github.com/RsyncProject/rsync / delete_in_dir

Function delete_in_dir

generator.c:279–354  ·  view source on GitHub ↗

This function is used to implement per-directory deletion, and is used by * all the --delete-WHEN options. Note that the fbuf pointer must point to a * MAXPATHLEN buffer with the name of the directory in it (the functions we * call will append names onto the end, but the old dir value will be restored * on exit). */

Source from the content-addressed store, hash-verified

277 * call will append names onto the end, but the old dir value will be restored
278 * on exit). */
279static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t fs_dev)
280{
281 static int already_warned = 0;
282 static struct hashtable *dev_tbl;
283 struct file_list *dirlist;
284 char delbuf[MAXPATHLEN];
285 int dlen, i;
286
287 if (!fbuf) {
288 change_local_filter_dir(NULL, 0, 0);
289 return;
290 }
291
292 if (DEBUG_GTE(DEL, 2))
293 rprintf(FINFO, "delete_in_dir(%s)\n", fbuf);
294
295 if (allowed_lull)
296 maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH);
297
298 if (io_error & IOERR_GENERAL && !ignore_errors) {
299 if (already_warned)
300 return;
301 rprintf(FINFO,
302 "IO error encountered -- skipping file deletion\n");
303 already_warned = 1;
304 return;
305 }
306
307 dlen = strlen(fbuf);
308 change_local_filter_dir(fbuf, dlen, F_DEPTH(file));
309
310 if (one_file_system) {
311 if (!dev_tbl)
312 dev_tbl = hashtable_create(16, HT_KEY64);
313 if (file->flags & FLAG_TOP_DIR) {
314 hashtable_find(dev_tbl, fs_dev+1, "");
315 filesystem_dev = fs_dev;
316 } else if (filesystem_dev != fs_dev) {
317 if (!hashtable_find(dev_tbl, fs_dev+1, NULL))
318 return;
319 filesystem_dev = fs_dev; /* it's a prior top-dir dev */
320 }
321 }
322
323 dirlist = get_dirlist(fbuf, dlen, 0);
324
325 /* If an item in dirlist is not found in flist, delete it
326 * from the filesystem. */
327 for (i = dirlist->used; i--; ) {
328 struct file_struct *fp = dirlist->files[i];
329 if (!F_IS_ACTIVE(fp))
330 continue;
331 if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) {
332 if (INFO_GTE(MOUNT, 1))
333 rprintf(FINFO, "cannot delete mount point: %s\n",
334 f_name(fp, NULL));
335 continue;
336 }

Callers 3

do_delete_passFunction · 0.85
recv_generatorFunction · 0.85
generate_filesFunction · 0.85

Calls 11

change_local_filter_dirFunction · 0.85
maybe_send_keepaliveFunction · 0.85
hashtable_createFunction · 0.85
hashtable_findFunction · 0.85
get_dirlistFunction · 0.85
f_nameFunction · 0.85
remember_deleteFunction · 0.85
delete_itemFunction · 0.85
flist_freeFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected