-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmain.c
More file actions
828 lines (715 loc) · 21.6 KB
/
main.c
File metadata and controls
828 lines (715 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/*
This file is part of rmw<https://theimpossibleastronaut.github.io/rmw-website/>
Copyright (C) 2012-2023 Andy Alt (arch_stanton5995@proton.me)
Other authors: https://github.com/theimpossibleastronaut/rmw/blob/master/AUTHORS.md
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "globals.h"
#include "main.h"
#include "utils.h"
#include "restore.h"
#include "config_rmw.h"
#include "purging.h"
#include "strings_rmw.h"
#include "messages.h"
#include "btrfs.h"
#include "trashinfo.h"
/*!
* Assigns a time string to *tm_str based on the format requested
*/
static void
set_time_string(char *tm_str, const size_t len, const char *format,
time_t time_t_now)
{
struct tm result;
if (localtime_r(&time_t_now, &result) == NULL)
{
fputs
("Error: localtime_r() failed for time_t value beyond 32-bit limit.\n",
stderr);
exit(EXIT_FAILURE);
}
strftime(tm_str, len, format, &result);
trim_whitespace(tm_str);
return;
}
/*!
* Returns a formatted string based on whether or not
* a fake year is requested at runtime. If a fake-year is not requested,
* the returned string will be based on the local-time of the user's system.
*/
static void
set_which_deletion_date(char *format)
{
char *fake_year = getenv("RMW_FAKE_YEAR");
bool valid_value = false;
if (fake_year != NULL)
{
valid_value = strcasecmp(fake_year, "true") == 0;
puts("RMW_FAKE_YEAR:true");
}
sn_check(snprintf
(format, LEN_MAX_DELETION_DATE, "%s",
valid_value ? "1999-%m-%dT%T" : "%FT%T"), LEN_MAX_DELETION_DATE);
return;
}
void
init_time_vars(st_time *x)
{
x->now = time(NULL);
// x->now = 0x80000000;
set_which_deletion_date(x->t_fmt);
set_time_string(x->deletion_date, LEN_MAX_DELETION_DATE, x->t_fmt, x->now);
set_time_string(x->suffix_added_dup_exists,
LEN_MAX_TIME_STR_SUFFIX, "_%H%M%S-%y%m%d", x->now);
return;
}
static int
process_mrl(st_waste *waste_head,
st_time *st_time_var,
const char *mrl_file, rmw_options *cli_user_options)
{
enum
{
MRL_IS_EMPTY = 10,
};
char *contents = NULL;
// fprintf(stderr, "mrl_file: %s\n", mrl_file);
bool backwards_compat_empty_header = false;
FILE *fp = fopen(mrl_file, "r");
if (fp != NULL)
{
fseek(fp, 0, SEEK_END); // move to the end of the file so we can use ftell()
const int f_size = ftell(fp); // Get the size of the file
rewind(fp);
contents = calloc(1, f_size + 1);
if (!contents)
fatal_malloc();
int n_items = fread(contents, 1, f_size + 1, fp);
if (n_items != f_size)
{
print_msg_warn();
fprintf(stdout, "ftell() returned %d, but fread() returned %d", f_size,
n_items);
}
if (feof(fp) == 0)
{
print_msg_error();
fprintf(stderr, "while reading %s\n", mrl_file);
clearerr(fp);
}
close_file(&fp, mrl_file, __func__);
contents[f_size] = '\0';
if (!strcmp(contents, "[Empty]\n"))
backwards_compat_empty_header = true;
}
else
{
if (errno == ENOENT)
{
// fprintf(stderr, "%d %s\n", errno, strerror(ENOENT));
puts(_("There are no items in the list - please check back later.\n"));
return MRL_IS_EMPTY;
}
else
{
fprintf(stderr, "open mrl failed: %s\n", strerror(errno));
return -1;
}
}
int res = 0;
if (cli_user_options->most_recent_list)
{
printf("%s", contents);
if (cli_user_options->want_undo)
puts(_
("Skipping --undo-last because --most-recent-list was requested"));
}
else
{
if (backwards_compat_empty_header == false)
res =
undo_last_rmw(st_time_var, cli_user_options, contents, waste_head);
if (res == 0)
{
if (cli_user_options->want_dry_run == false)
if (unlink(mrl_file) != 0)
fprintf(stderr, "unlink: %s \n%s in %s\n", mrl_file,
strerror(errno), __func__);
}
}
free(contents);
return res;
}
/*!
* When a file has been successfully rmw'ed, add the filename to
* a linked list.
*/
static st_removed *
add_removal(st_removed *removals, const char *file)
{
if (removals == NULL)
{
st_removed *temp_node = (st_removed *) malloc(sizeof(st_removed));
if (!temp_node)
fatal_malloc();
removals = temp_node;
}
else
{
if (!(removals->next_node = (st_removed *) malloc(sizeof(st_removed))))
fatal_malloc();
removals = removals->next_node;
}
removals->next_node = NULL;
bufchk_len(strlen(file) + 1, sizeof removals->file, __func__, __LINE__);
strcpy(removals->file, file);
return removals;
}
/*!
* Create a new undo_file (lastrmw)
*/
static void
create_undo_file(st_removed *removals_head, const char *mrl_file)
{
FILE *fp = fopen(mrl_file, "w");
if (fp)
{
st_removed *st_removals_list = removals_head;
while (st_removals_list != NULL)
{
fprintf(fp, "%s\n", st_removals_list->file);
st_removals_list = st_removals_list->next_node;
}
close_file(&fp, mrl_file, __func__);
}
else
open_err(mrl_file, __func__);
return;
}
/*!
* recursively remove all nodes of an object of type @ref st_removed
*/
static void
dispose_removed(st_removed *node)
{
if (node != NULL)
{
dispose_removed(node->next_node);
free(node);
}
return;
}
static void
list_waste_folders(st_waste *waste_head)
{
// Directories that are not on attached medium are not included in
// the waste linked list, so we can just assign true here.
const bool is_attached = true;
st_waste *waste_curr = waste_head;
while (waste_curr != NULL)
{
show_folder_line(waste_curr->parent, waste_curr->removable, is_attached);
waste_curr = waste_curr->next_node;
}
dispose_waste(waste_head);
return;
}
static int
remove_to_waste(const int argc,
char *const argv[],
st_waste *waste_head,
st_time *st_time_var,
const st_loc *st_location,
const rmw_options *cli_user_options)
{
rmw_target st_target;
st_removed *confirmed_removals_list = NULL;
st_removed *confirmed_removals_list_head = NULL;
int n_err = 0;
int removed_files_ctr = 0;
int file_arg;
for (file_arg = optind; file_arg < argc; file_arg++)
{
if (*argv[file_arg] == '\0')
{
puts("skipping empty string");
continue;
}
char tmp[PATH_MAX];
sn_check(snprintf(tmp, sizeof(tmp), "%s", argv[file_arg]), sizeof(tmp));
// If basename() is given an empty string, it returns '.'
st_target.base_name = basename(tmp);
if (isdotdir(st_target.base_name))
{
printf("refusing to ReMove '.' or '..' directory: skipping '%s'\n",
argv[file_arg]);
continue;
}
/* leave "/" or "\" alone */
if (strcmp(argv[file_arg], "/") == 0 || strcmp(argv[file_arg], "/") == 0)
{
puts(_("\n\
Your single slash has been ignored. You walk to the market\n\
in the town square and purchase a Spear of Destiny. You walk to\n\
the edge of the forest and find your enemy. You attack, causing\n\
damage of 5000 hp. You feel satisfied.\n"));
continue;
}
int p_state = check_pathname_state(argv[file_arg]);
if (p_state != EEXIST)
{
if (p_state == ENOENT)
msg_warn_file_not_found(argv[file_arg]);
continue;
}
struct stat st_file_arg;
if (!lstat(argv[file_arg], &st_file_arg))
{
st_target.dev_num = st_file_arg.st_dev;
st_target.real_path = resolve_path(argv[file_arg], st_target.base_name);
if (st_target.real_path == NULL)
{
n_err++;
continue;
}
}
else
{
print_msg_warn();
printf("lstat: (argv[file_arg]) %s\n", strerror(errno));
continue;
}
if (strcmp(st_target.real_path, st_location->home_dir) == 0)
{
puts(_("Skipping requested ReMoval of your HOME directory"));
free(st_target.real_path);
continue;
}
if (!cli_user_options->want_top_level_bypass)
{
if (count_chars('/', st_target.real_path) == 1)
{
printf(_("Skipping requested ReMoval of %s\n"), st_target.real_path);
free(st_target.real_path);
continue;
}
}
/* Make sure the file isn't a waste folder or a file within a waste folder */
bool is_protected = 0;
st_waste *waste_curr = waste_head;
while (waste_curr != NULL)
{
if (strncmp
(waste_curr->parent, st_target.real_path,
strlen(waste_curr->parent)) == 0)
{
print_msg_warn();
printf(_("%s resides within a waste folder and has been ignored\n"),
argv[file_arg]);
is_protected = 1;
if (getenv("RMW_FAKE_HOME"))
n_err++;
break;
}
waste_curr = waste_curr->next_node;
}
if (is_protected)
{
free(st_target.real_path);
continue;
}
/**
* cycle through wasteDirs to see which one matches
* device number of file.orig. Once found, the ReMoval
* happens (provided all the tests are passed.
*/
waste_curr = waste_head;
while (waste_curr != NULL)
{
if (waste_curr->dev_num == st_target.dev_num ||
(waste_curr->is_btrfs && is_btrfs(argv[file_arg])))
{
char *tmp_str = join_paths(waste_curr->files, st_target.base_name);
// *st_target.waste_dest_name = '\0';
strcpy(st_target.waste_dest_name, tmp_str);
free(tmp_str);
tmp_str = NULL;
/* If a duplicate file exists
*/
if ((st_target.is_duplicate =
(check_pathname_state(st_target.waste_dest_name)) == EEXIST))
{
// append a time string
bufchk_len(strlen(st_target.waste_dest_name) +
LEN_MAX_TIME_STR_SUFFIX,
sizeof st_target.waste_dest_name, __func__, __LINE__);
strcat(st_target.waste_dest_name,
st_time_var->suffix_added_dup_exists);
}
int r_result = 0;
if (cli_user_options->want_dry_run == false)
{
if ((waste_curr->dev_num != st_target.dev_num) && !S_ISDIR(st_file_arg.st_mode))
{
int save_errno = errno;
r_result =
do_btrfs_clone(argv[file_arg], st_target.waste_dest_name,
&save_errno);
if (r_result != 0)
{
if (save_errno == EXDEV)
{
waste_curr = waste_curr->next_node;
continue;
}
else
exit(EXIT_FAILURE);
}
}
else
{
r_result = rename(argv[file_arg], st_target.waste_dest_name);
}
}
if (r_result == 0)
{
if (verbose)
printf("'%s' -> '%s'\n", argv[file_arg],
st_target.waste_dest_name);
removed_files_ctr++;
if (cli_user_options->want_dry_run == false)
if (!create_trashinfo(&st_target, waste_curr, st_time_var))
{
free(st_target.real_path);
confirmed_removals_list =
add_removal(confirmed_removals_list,
st_target.waste_dest_name);
if (confirmed_removals_list_head == NULL)
confirmed_removals_list_head = confirmed_removals_list;
}
}
else
msg_err_rename(argv[file_arg], st_target.waste_dest_name);
/**
* If we get to this point, it means a WASTE folder was found
* that matches the file system that file->orig was on.
* breaking from the for loop
*/
break;
}
/* If the file didn't match with a waste folder on the same filesystem,
* try the next waste folder */
waste_curr = waste_curr->next_node;
}
if (!waste_curr)
{
printf(_(" :'%s' not ReMoved:\n"), argv[file_arg]);
printf(_
("No WASTE folder defined in '%s' that resides on the same filesystem.\n"),
st_location->config_file);
free(st_target.real_path);
}
}
if (confirmed_removals_list_head != NULL)
{
create_undo_file(confirmed_removals_list_head, st_location->mrl_file);
dispose_removed(confirmed_removals_list_head);
}
printf(ngettext
("%d item was removed to the waste folder",
"%d items were removed to the waste folder", removed_files_ctr),
removed_files_ctr);
putchar('\n');
return n_err;
}
// Returns a struct containing the absolute path of the user's home,
// dataroot, and configroot directories. If $XDG_DATA_HOME or $XDG_CONFIG_HOME
// exist as environmental variables, those will be used. Otherwise dataroot
// will be appended to $HOME as '/.local/share' and configroot will be
// appended as '/.config'.
//
// TODO: make it compatible with Windows systems.
static const st_dir *
get_directories(void)
{
static st_dir st_directory;
st_directory.home = getenv("HOME");
if (st_directory.home == NULL)
return NULL;
const char *xdg_configroot = getenv("XDG_CONFIG_HOME");
if (xdg_configroot == NULL)
snprintf(st_directory.configroot,
sizeof st_directory.configroot, "%s/.config", st_directory.home);
else
snprintf(st_directory.configroot,
sizeof st_directory.configroot, "%s", xdg_configroot);
const char *xdg_dataroot = getenv("XDG_DATA_HOME");
if (xdg_dataroot == NULL)
snprintf(st_directory.dataroot,
sizeof st_directory.dataroot,
"%s/.local/share", st_directory.home);
else
snprintf(st_directory.dataroot,
sizeof st_directory.dataroot, "%s", xdg_dataroot);
return &st_directory;
}
static const st_loc *
get_locations(const char *alt_config_file)
{
const char rel_default_data_dir[] = ".local/share/rmw";
const char rel_default_config_dir[] = ".config";
const char config_file_basename[] = "rmwrc";
const char mrl_file_basename[] = "mrl";
const char purge_time_file_basename[] = "purge-time";
static st_loc x;
x.st_directory = get_directories();
if (x.st_directory == NULL)
return NULL;
const char *enable_test = getenv(ENV_RMW_FAKE_HOME);
static char s_data_dir[PATH_MAX];
char *m_d_str = NULL;
static char s_config_dir[PATH_MAX];
if (enable_test == NULL)
{
x.home_dir = x.st_directory->home;
m_d_str = join_paths(x.st_directory->dataroot, PACKAGE_STRING);
x.config_dir = x.st_directory->configroot;
}
else
{
if (verbose)
printf("%s:%s\n", ENV_RMW_FAKE_HOME, enable_test);
x.home_dir = enable_test;
m_d_str = join_paths(x.home_dir, rel_default_data_dir);
char *m_c_str = join_paths(x.home_dir, rel_default_config_dir);
sn_check(snprintf(s_config_dir, sizeof s_config_dir, "%s", m_c_str),
sizeof s_config_dir);
free(m_c_str);
x.config_dir = s_config_dir;
}
sn_check(snprintf(s_data_dir, sizeof s_data_dir, "%s", m_d_str),
sizeof s_data_dir);
free(m_d_str);
x.data_dir = s_data_dir;
if (verbose)
{
printf("home_dir: %s\n", x.home_dir);
printf("data_dir: %s\n", x.data_dir);
printf("config_dir: %s\n", x.config_dir);
}
int p_state = check_pathname_state(x.config_dir);
if (p_state == ENOENT)
{
if (!rmw_mkdir(x.config_dir))
msg_success_mkdir(x.config_dir);
else
{
msg_err_mkdir(x.config_dir, __func__);
exit(errno);
}
}
else if (p_state == -1)
exit(p_state);
static char s_config_file[PATH_MAX];
if (alt_config_file == NULL)
{
char *tmp_str = join_paths(x.config_dir, config_file_basename);
sn_check(snprintf(s_config_file, sizeof s_config_file, "%s", tmp_str),
sizeof s_config_file);
free(tmp_str);
x.config_file = s_config_file;
}
else
x.config_file = alt_config_file;
if (verbose)
printf("config_file: %s\n", x.config_file);
if ((p_state = check_pathname_state(x.config_file)) == ENOENT)
{
FILE *fp = fopen(x.config_file, "w");
if (fp)
{
puts(_("Creating default configuration file:"));
printf(" %s\n\n", x.config_file);
print_config(fp);
close_file(&fp, x.config_file, __func__);
}
else
{
open_err(x.config_file, __func__);
puts(_("Unable to read or write a configuration file."));
exit(errno);
}
}
else if (p_state == -1)
exit(p_state);
static char s_mrl_file[PATH_MAX];
char *m_tmp_str = join_paths(x.data_dir, mrl_file_basename);
sn_check(snprintf(s_mrl_file, sizeof s_mrl_file, "%s", m_tmp_str),
sizeof s_mrl_file);
free(m_tmp_str);
x.mrl_file = s_mrl_file;
static char s_purge_time_file[PATH_MAX];
m_tmp_str = join_paths(x.data_dir, purge_time_file_basename);
sn_check(snprintf
(s_purge_time_file, sizeof s_purge_time_file, "%s", m_tmp_str),
sizeof s_purge_time_file);
free(m_tmp_str);
x.purge_time_file = s_purge_time_file;
if (verbose)
{
printf("mrl_file: %s\n", x.mrl_file);
printf("purge_time_file: %s\n", x.purge_time_file);
}
return &x;
}
int
main(const int argc, char *const argv[])
{
#ifdef ENABLE_NLS
static char *locale_dir;
locale_dir = getenv("RMW_LOCALEDIR");
if (!locale_dir)
locale_dir = LOCALEDIR;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE_STRING, locale_dir);
textdomain(PACKAGE_STRING);
#endif
rmw_options cli_user_options;
init_rmw_options(&cli_user_options);
parse_cli_options(argc, argv, &cli_user_options);
if (verbose > 1)
printf("PATH_MAX = %d\n", PATH_MAX);
if (verbose > 0)
#ifdef HAVE_LINUX_BTRFS
puts("btrfs_clone support: true");
#else
puts("btrfs_clone support: false");
#endif
const st_loc *st_location = get_locations(cli_user_options.alt_config_file);
if (st_location == NULL)
{
print_msg_error();
fputs(_("while getting the path to your home directory\n"), stderr);
return 1;
}
int p_state = 0;
if ((p_state = check_pathname_state(st_location->data_dir)) == -1)
exit(p_state);
bool init_data_dir = (p_state == ENOENT);
if (init_data_dir)
{
if (!rmw_mkdir(st_location->data_dir))
{
msg_success_mkdir(st_location->data_dir);
}
else
{
msg_err_mkdir(st_location->data_dir, __func__);
printf(_("\
unable to create config and data directory\n\
Please check your configuration file and permissions\
\n\
\n"));
printf(_("Unable to continue. Exiting...\n"));
return errno;
}
}
st_config st_config_data;
init_config_data(&st_config_data);
parse_config_file(&cli_user_options, &st_config_data, st_location);
if (cli_user_options.list)
{
list_waste_folders(st_config_data.st_waste_folder_props_head);
return 0;
}
st_time st_time_var;
init_time_vars(&st_time_var);
int orphan_ctr = 0;
if (cli_user_options.want_purge
|| is_time_to_purge(&st_time_var, st_location->purge_time_file))
{
if (!st_config_data.force_required || cli_user_options.force)
purge(&st_config_data, &cli_user_options, &st_time_var, &orphan_ctr);
else
printf(_("purge has been skipped: use -f or --force\n"));
}
if (cli_user_options.want_orphan_chk)
{
orphan_maint(st_config_data.st_waste_folder_props_head, &st_time_var,
&orphan_ctr);
dispose_waste(st_config_data.st_waste_folder_props_head);
return 0;
}
if (cli_user_options.want_selection_menu)
{
int r = 0;
#if !defined DISABLE_CURSES
r =
restore_select(st_config_data.st_waste_folder_props_head, &st_time_var,
&cli_user_options);
#else
printf("This rmw was built without menu support\n");
r = 0;
#endif
dispose_waste(st_config_data.st_waste_folder_props_head);
return r;
}
if (cli_user_options.most_recent_list || cli_user_options.want_undo)
{
int res =
process_mrl(st_config_data.st_waste_folder_props_head, &st_time_var,
st_location->mrl_file, &cli_user_options);
dispose_waste(st_config_data.st_waste_folder_props_head);
return res;
}
if (cli_user_options.want_restore)
{
int r = 0;
/* subtract 1 from optind otherwise the first file in the list isn't
* restored
*/
int file_arg = 0;
for (file_arg = optind - 1; file_arg < argc; file_arg++)
{
if (restore(argv[file_arg], &st_time_var, &cli_user_options,
st_config_data.st_waste_folder_props_head) != 0)
r++;
}
dispose_waste(st_config_data.st_waste_folder_props_head);
return r;
}
if (optind < argc)
{
int result = remove_to_waste(argc,
argv,
st_config_data.st_waste_folder_props_head,
&st_time_var,
st_location,
&cli_user_options);
if (result)
{
dispose_waste(st_config_data.st_waste_folder_props_head);
/* Don't need to print any messages here. Any warnings or errors
* should have been sent to stdout when they happened */
return result;
}
}
else if (!cli_user_options.want_purge &&
!cli_user_options.want_empty_trash && !init_data_dir)
{
printf(_("Insufficient command line arguments given;\n\
Enter '%s -h' for more information\n"), argv[0]);
}
dispose_waste(st_config_data.st_waste_folder_props_head);
return 0;
}