Roxen.git
/
server
/
base_server
/
fsgc.pike
version
»
Context lines:
10
20
40
80
file
none
3
Roxen.git/server/base_server/fsgc.pike:46:
string modid; string root; int max_age; int max_files; int max_size; mapping(string:object) handle_lookup = ([]); ADT.Priority_queue pending_gc = ADT.Priority_queue();
-
#ifdef
FSGC_PRETEND
+
//! If set, move files to this directory instead of deleting them.
+
//!
+
//! If set to @[root] or @expr{""@} keep the files as is.
+
string quarantine;
+
protected int rm(string path) {
-
werror
("FSGC: Zap %O\n", path);
+
GC_WERR
("FSGC: Zap %O\n", path);
+
if (quarantine) {
+
if ((quarantine == root) || (quarantine == "")) return 0;
+
if (!has_prefix(path, root)) return 0;
+
string rel = path[sizeof(root)..];
+
+
// First try the trivial case.
+
if (mv(path, quarantine + rel)) return 1;
+
+
string dirs = dirname(rel);
+
if (sizeof(dirs)) {
+
if (Stdio.mkdirhier(quarantine + dirs)) {
+
// Try again with the directory existing.
+
if (mv(path, quarantine + rel)) return 1;
}
-
#endif
+
}
-
+
// Different filesystems?
+
if (Stdio.cp(path, quarantine + rel)) {
+
return predef::rm(path);
+
}
+
werror("FSGC: Failed to copy file %O to %O: %s.\n",
+
path, quarantine + rel, strerror(errno()));
+
return 0;
+
} else {
+
return predef::rm(path);
+
}
+
}
+
void check_threshold() { GC_WERR("FSGC: Checking thresholds...\n" " total_size: %d max_size: %d\n" " num_files: %d max_files: %d\n", total_size, max_size, num_files, max_files); while ((max_size && (total_size > max_size)) || (max_files && (num_files > max_files))) {
Roxen.git/server/base_server/fsgc.pike:295:
total_size -= old_st->size; remove_pending(this); check_threshold(); } } } protected void create(string modid, string path, int max_age,
-
int|void max_size, int|void max_files)
+
int|void max_size, int|void max_files
,
+
string|void quarantine
)
{ GC_WERR("FSGC: Max age: %d\n", max_age); GC_WERR("FSGC: Max size: %d\n", max_size); GC_WERR("FSGC: Max files: %d\n", max_files); this_program::modid = modid; this_program::max_age = max_age; this_program::max_size = max_size; this_program::max_files = max_files; root = canonic_path(path);
-
+
if (quarantine) {
+
if (sizeof(quarantine)) {
+
quarantine = canonic_path(quarantine);
+
}
+
this::quarantine = quarantine;
+
}
+
::create(max_age/file_interval_factor, 0, max_age); // Workaround for too strict type-check in Pike 7.8. int flags = 3; monitor(root, flags); } void stable_data_change(string path, Stdio.Stat st) {
Roxen.git/server/base_server/fsgc.pike:422:
} void reconfigure(int max_age, int|void max_size, int|void max_files) { FSGarb g = fsgarbs[id]; if (g) g->reconfigure(max_age, max_size, max_files); } } FSGarbWrapper register_fsgarb(string modid, string path, int max_age,
-
int|void max_size, int|void max_files)
+
int|void max_size, int|void max_files
,
+
string|void quarantine
)
{ if ((path == "") || (path == "/") || (max_age <= 0)) return 0; string id = modid + "\0" + path + "\0" + gethrtime();
-
FSGarb g = FSGarb(modid, path, max_age, max_size, max_files);
+
FSGarb g = FSGarb(modid, path, max_age, max_size, max_files
,
+
quarantine
);
fsgarbs[id] = g; GC_WERR("FSGC: Register garb on %O ==> id: %O\n", path, id); return FSGarbWrapper(id); } void name_thread(object thread, string name); protected void start_fsgarb() { meta_fsgc_thread = Thread.Thread(meta_fsgc);