Skip to content

Commit a3070c9

Browse files
committed
gufi_rollup --delete-below <level>
users probably won't be querying starting at level 100, so delete rollup under provided level to save storage space removed --max-level because that does not make sense for rollups
1 parent 14fab86 commit a3070c9

File tree

6 files changed

+366
-150
lines changed

6 files changed

+366
-150
lines changed

include/bf.h

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ extern "C" {
171171
#define FLAG_GROUP_MEM 2000
172172
#define FLAG_GROUP_XATTRS 3000
173173
#define FLAG_GROUP_INC 4000
174+
#define FLAG_GROUP_ROLLUP 5000
174175

175176
/* miscellaneous flags */
176177

@@ -218,35 +219,31 @@ extern "C" {
218219
#define FLAG_TERSE_LONG "terse"
219220
#define FLAG_TERSE {FLAG_TERSE_LONG, no_argument, NULL, FLAG_TERSE_SHORT}
220221

221-
#define FLAG_ROLLUP_LIMIT_SHORT (FLAG_GROUP_MISC + 11)
222-
#define FLAG_ROLLUP_LIMIT_LONG "limit"
223-
#define FLAG_ROLLUP_LIMIT {FLAG_ROLLUP_LIMIT_LONG, required_argument, NULL, FLAG_ROLLUP_LIMIT_SHORT}
224-
225-
#define FLAG_DONT_REPROCESS_SHORT (FLAG_GROUP_MISC + 12)
222+
#define FLAG_DONT_REPROCESS_SHORT (FLAG_GROUP_MISC + 11)
226223
#define FLAG_DONT_REPROCESS_LONG "dont-reprocess"
227224
#define FLAG_DONT_REPROCESS {FLAG_DONT_REPROCESS_LONG, no_argument, NULL, FLAG_DONT_REPROCESS_SHORT}
228225

229-
#define FLAG_NEWLINE_SHORT (FLAG_GROUP_MISC + 13)
226+
#define FLAG_NEWLINE_SHORT (FLAG_GROUP_MISC + 12)
230227
#define FLAG_NEWLINE_LONG "newline"
231228
#define FLAG_NEWLINE {FLAG_NEWLINE_LONG, required_argument, NULL, FLAG_NEWLINE_SHORT}
232229

233-
#define FLAG_SUPPRESS_NEWLINE_SHORT (FLAG_GROUP_MISC + 14)
230+
#define FLAG_SUPPRESS_NEWLINE_SHORT (FLAG_GROUP_MISC + 13)
234231
#define FLAG_SUPPRESS_NEWLINE_LONG "suppress-newline"
235232
#define FLAG_SUPPRESS_NEWLINE {FLAG_SUPPRESS_NEWLINE_LONG, no_argument, NULL, FLAG_SUPPRESS_NEWLINE_SHORT}
236233

237-
#define FLAG_DIR_MATCH_UID_SHORT (FLAG_GROUP_MISC + 15)
234+
#define FLAG_DIR_MATCH_UID_SHORT (FLAG_GROUP_MISC + 14)
238235
#define FLAG_DIR_MATCH_UID_LONG "dir-match-uid"
239236
#define FLAG_DIR_MATCH_UID {FLAG_DIR_MATCH_UID_LONG, optional_argument, NULL, FLAG_DIR_MATCH_UID_SHORT}
240237

241-
#define FLAG_DIR_MATCH_GID_SHORT (FLAG_GROUP_MISC + 16)
238+
#define FLAG_DIR_MATCH_GID_SHORT (FLAG_GROUP_MISC + 15)
242239
#define FLAG_DIR_MATCH_GID_LONG "dir-match-gid"
243240
#define FLAG_DIR_MATCH_GID {FLAG_DIR_MATCH_GID_LONG, optional_argument, NULL, FLAG_DIR_MATCH_GID_SHORT}
244241

245-
#define FLAG_PRINT_EACCES_SHORT (FLAG_GROUP_MISC + 17)
242+
#define FLAG_PRINT_EACCES_SHORT (FLAG_GROUP_MISC + 16)
246243
#define FLAG_PRINT_EACCES_LONG "print-eacces"
247244
#define FLAG_PRINT_EACCES {FLAG_PRINT_EACCES_LONG, no_argument, NULL, FLAG_PRINT_EACCES_SHORT}
248245

249-
#define FLAG_NO_PRINT_SQL_ON_ERR_SHORT (FLAG_GROUP_MISC + 18)
246+
#define FLAG_NO_PRINT_SQL_ON_ERR_SHORT (FLAG_GROUP_MISC + 17)
250247
#define FLAG_NO_PRINT_SQL_ON_ERR_LONG "no-print-sql-on-err"
251248
#define FLAG_NO_PRINT_SQL_ON_ERR {FLAG_NO_PRINT_SQL_ON_ERR_LONG, no_argument, NULL, FLAG_NO_PRINT_SQL_ON_ERR_SHORT}
252249

@@ -308,6 +305,16 @@ extern "C" {
308305
#define FLAG_SUSPECT_STAT_LONG "suspect-stat"
309306
#define FLAG_SUSPECT_STAT {FLAG_SUSPECT_STAT_LONG, no_argument, NULL, FLAG_SUSPECT_STAT_SHORT}
310307

308+
/* gufi_rollup flags */
309+
310+
#define FLAG_ROLLUP_LIMIT_SHORT (FLAG_GROUP_ROLLUP + 0)
311+
#define FLAG_ROLLUP_LIMIT_LONG "limit"
312+
#define FLAG_ROLLUP_LIMIT {FLAG_ROLLUP_LIMIT_LONG, required_argument, NULL, FLAG_ROLLUP_LIMIT_SHORT}
313+
314+
#define FLAG_ROLLUP_DELETE_BELOW_SHORT (FLAG_GROUP_ROLLUP + 1)
315+
#define FLAG_ROLLUP_DELETE_BELOW_LONG "delete-below"
316+
#define FLAG_ROLLUP_DELETE_BELOW {FLAG_ROLLUP_DELETE_BELOW_LONG, required_argument, NULL, FLAG_ROLLUP_DELETE_BELOW_SHORT}
317+
311318
/* required at the end of every flag list */
312319
#define FLAG_END {NULL, 0, NULL, 0}
313320

@@ -514,7 +521,10 @@ struct input {
514521
str_t format;
515522

516523
/* only used by rollup */
517-
size_t rollup_entries_limit;
524+
struct {
525+
size_t entries_limit;
526+
size_t delete_below;
527+
} rollup;
518528

519529
/* trie containing directory basenames to skip during tree traversal */
520530
trie_t *skip;

src/bf.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct input *input_init(struct input *in) {
123123
in->output = STDOUT;
124124
in->output_buffer_size = 4096;
125125
in->open_flags = SQLITE_OPEN_READONLY; // default to read-only opens
126+
in->rollup.delete_below = -1;
126127
in->skip = trie_alloc();
127128

128129
/* always skip . and .. */
@@ -251,7 +252,6 @@ void print_help(const char* prog_name,
251252
case FLAG_PATH_LIST_SHORT: printf(" --path-list <filename> File containing paths at single level to walk (not including starting path). If --min-level > 0, prepend each line of the file with the index path."); break;
252253
case FLAG_FORMAT_SHORT: printf(" --format <FORMAT> use the specified FORMAT instead of the default; output a newline after each use of FORMAT"); break;
253254
case FLAG_TERSE_SHORT: printf(" --terse print the information in terse form"); break; /* output from stat --help */
254-
case FLAG_ROLLUP_LIMIT_SHORT: printf(" --limit <count> Highest number of files/links in a directory allowed to be rolled up"); break;
255255
case FLAG_DONT_REPROCESS_SHORT: printf(" --dont-reprocess if a directory was previously processed, skip descending the subtree"); break;
256256
case FLAG_NEWLINE_SHORT: printf(" --newline <c> character used to separate lines (default: '\\n') [use 0 for NULL character]"); break;
257257
case FLAG_SUPPRESS_NEWLINE_SHORT: printf(" --suppress-newline do not print the line separator"); break;
@@ -277,6 +277,10 @@ void print_help(const char* prog_name,
277277
case FLAG_SUSPECT_TIME_SHORT: printf(" --suspect-time <s> time in seconds since epoch for suspect comparision"); break;
278278
case FLAG_SUSPECT_STAT_SHORT: printf(" --suspect-stat if an entry is suspect, stat it to get timestamps to compare against suspecttime"); break;
279279

280+
/* gufi_rollup flags */
281+
case FLAG_ROLLUP_LIMIT_SHORT: printf(" --limit <count> Highest number of files/links in a directory allowed to be rolled up"); break;
282+
case FLAG_ROLLUP_DELETE_BELOW_SHORT: printf(" --delete-below <level> Delete rollup data under (not including) this level"); break;
283+
280284
default: printf("print_help(): unrecognized option '%c'", (char)options->val); break;
281285
}
282286
options++;
@@ -331,7 +335,6 @@ void show_input(struct input* in, int retval) {
331335
printf("in.format_set = %d\n", in->format_set);
332336
printf("in.format = '%s'\n", in->format.data);
333337
printf("in.terse = %d\n", in->terse);
334-
printf("in.rollup_entries_limit = %zu\n", in->rollup_entries_limit);
335338
printf("in.dont_reprocess = %d\n", in->dont_reprocess);
336339
printf("in.newline = '%c'\n", in->newline);
337340
printf("in.suppress_newline = %d\n", in->suppress_newline);
@@ -350,13 +353,17 @@ void show_input(struct input* in, int retval) {
350353

351354
printf("in.process_xattrs = %d\n", in->process_xattrs);
352355

353-
/* gufi_incremental_update */
356+
/* gufi_incremental_update flags */
354357
printf("in.insuspect = '%s'\n", in->insuspect.data);
355358
printf("in.suspectfile = '%d'\n", in->suspectfile);
356359
printf("in.suspectmethod = '%d'\n", in->suspectmethod);
357360
printf("in.suspecttime = '%d'\n", in->suspecttime);
358361
printf("in.suspectstat = '%d'\n", in->suspectstat);
359362

363+
/* gufi_rollup flags */
364+
printf("in.rollup.entries_limit = %zu\n", in->rollup.entries_limit);
365+
printf("in.rollup.delete_below = %zu\n", in->rollup.delete_below);
366+
360367
printf("retval = %d\n", retval);
361368
printf("\n");
362369
}
@@ -623,11 +630,6 @@ int parse_cmd_line(int argc,
623630
in->terse = 1;
624631
break;
625632

626-
case FLAG_ROLLUP_LIMIT_SHORT:
627-
INSTALL_SIZE(&in->rollup_entries_limit, optarg, (size_t) 0, (size_t) -1,
628-
"--" FLAG_ROLLUP_LIMIT_LONG, &retval);
629-
break;
630-
631633
case FLAG_DONT_REPROCESS_SHORT:
632634
in->dont_reprocess = 1;
633635
break;
@@ -703,7 +705,7 @@ int parse_cmd_line(int argc,
703705
in->process_xattrs = 1; /* all xattr flags point to the same variable */
704706
break;
705707

706-
/* gufi_incremental_update */
708+
/* gufi_incremental_update flags */
707709

708710
case FLAG_SUSPECT_FILE_SHORT:
709711
INSTALL_STR(&in->insuspect, optarg);
@@ -725,6 +727,18 @@ int parse_cmd_line(int argc,
725727
in->suspectstat = 1;
726728
break;
727729

730+
/* gufi_rollup flags */
731+
732+
case FLAG_ROLLUP_LIMIT_SHORT:
733+
INSTALL_SIZE(&in->rollup.entries_limit, optarg, (size_t) 0, (size_t) -1,
734+
"--" FLAG_ROLLUP_LIMIT_LONG, &retval);
735+
break;
736+
737+
case FLAG_ROLLUP_DELETE_BELOW_SHORT:
738+
INSTALL_SIZE(&in->rollup.delete_below, optarg, (size_t) 0, (size_t) -1,
739+
"--" FLAG_ROLLUP_DELETE_BELOW_LONG, &retval);
740+
break;
741+
728742
case '?':
729743
/* getopt_long prints an error message and returns '?' when there is a problem. */
730744
retval = -1;

0 commit comments

Comments
 (0)