Skip to content

Commit 67adf0c

Browse files
committed
gufi_rollup --delete-below <level>
users probably won't be querying starting at a low level, so delete rollup data under provided level to save storage space can combine with --min-level to limit storing rollup data between 2 levels
1 parent 14fab86 commit 67adf0c

File tree

6 files changed

+425
-143
lines changed

6 files changed

+425
-143
lines changed

include/bf.h

Lines changed: 23 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,11 @@ 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+
int attach_flag; /* SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE; set by --delete-below */
528+
} rollup;
518529

519530
/* trie containing directory basenames to skip during tree traversal */
520531
trie_t *skip;

src/bf.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ 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;
127+
in->rollup.attach_flag = SQLITE_OPEN_READONLY;
126128
in->skip = trie_alloc();
127129

128130
/* always skip . and .. */
@@ -251,7 +253,6 @@ void print_help(const char* prog_name,
251253
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;
252254
case FLAG_FORMAT_SHORT: printf(" --format <FORMAT> use the specified FORMAT instead of the default; output a newline after each use of FORMAT"); break;
253255
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;
255256
case FLAG_DONT_REPROCESS_SHORT: printf(" --dont-reprocess if a directory was previously processed, skip descending the subtree"); break;
256257
case FLAG_NEWLINE_SHORT: printf(" --newline <c> character used to separate lines (default: '\\n') [use 0 for NULL character]"); break;
257258
case FLAG_SUPPRESS_NEWLINE_SHORT: printf(" --suppress-newline do not print the line separator"); break;
@@ -277,6 +278,10 @@ void print_help(const char* prog_name,
277278
case FLAG_SUSPECT_TIME_SHORT: printf(" --suspect-time <s> time in seconds since epoch for suspect comparision"); break;
278279
case FLAG_SUSPECT_STAT_SHORT: printf(" --suspect-stat if an entry is suspect, stat it to get timestamps to compare against suspecttime"); break;
279280

281+
/* gufi_rollup flags */
282+
case FLAG_ROLLUP_LIMIT_SHORT: printf(" --limit <count> Highest number of files/links in a directory allowed to be rolled up"); break;
283+
case FLAG_ROLLUP_DELETE_BELOW_SHORT: printf(" --delete-below <level> Delete rollup data under (not including) this level"); break;
284+
280285
default: printf("print_help(): unrecognized option '%c'", (char)options->val); break;
281286
}
282287
options++;
@@ -331,7 +336,6 @@ void show_input(struct input* in, int retval) {
331336
printf("in.format_set = %d\n", in->format_set);
332337
printf("in.format = '%s'\n", in->format.data);
333338
printf("in.terse = %d\n", in->terse);
334-
printf("in.rollup_entries_limit = %zu\n", in->rollup_entries_limit);
335339
printf("in.dont_reprocess = %d\n", in->dont_reprocess);
336340
printf("in.newline = '%c'\n", in->newline);
337341
printf("in.suppress_newline = %d\n", in->suppress_newline);
@@ -350,13 +354,18 @@ void show_input(struct input* in, int retval) {
350354

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

353-
/* gufi_incremental_update */
357+
/* gufi_incremental_update flags */
354358
printf("in.insuspect = '%s'\n", in->insuspect.data);
355359
printf("in.suspectfile = '%d'\n", in->suspectfile);
356360
printf("in.suspectmethod = '%d'\n", in->suspectmethod);
357361
printf("in.suspecttime = '%d'\n", in->suspecttime);
358362
printf("in.suspectstat = '%d'\n", in->suspectstat);
359363

364+
/* gufi_rollup flags */
365+
printf("in.rollup.entries_limit = %zu\n", in->rollup.entries_limit);
366+
printf("in.rollup.delete_below = %zu\n", in->rollup.delete_below);
367+
printf("in.rollup.attach_flag = %d\n", in->rollup.attach_flag);
368+
360369
printf("retval = %d\n", retval);
361370
printf("\n");
362371
}
@@ -623,11 +632,6 @@ int parse_cmd_line(int argc,
623632
in->terse = 1;
624633
break;
625634

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-
631635
case FLAG_DONT_REPROCESS_SHORT:
632636
in->dont_reprocess = 1;
633637
break;
@@ -703,7 +707,7 @@ int parse_cmd_line(int argc,
703707
in->process_xattrs = 1; /* all xattr flags point to the same variable */
704708
break;
705709

706-
/* gufi_incremental_update */
710+
/* gufi_incremental_update flags */
707711

708712
case FLAG_SUSPECT_FILE_SHORT:
709713
INSTALL_STR(&in->insuspect, optarg);
@@ -725,6 +729,19 @@ int parse_cmd_line(int argc,
725729
in->suspectstat = 1;
726730
break;
727731

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

0 commit comments

Comments
 (0)