310
public SimpleSettings get_settings(string? subdir = null)
310
public FilteredSettings get_settings(string? subdir = null)
312
312
string schema = "org.gnome.DejaDup";
313
313
if (subdir != null && subdir != "")
314
314
schema += "." + subdir;
316
316
if (settings_read_only) {
317
317
rv = settings_table.lookup(schema);
318
318
if (rv == null) {
319
rv = new SimpleSettings(schema, true);
319
rv = new FilteredSettings(schema, true);
320
320
rv.delay(); // never to be apply()'d again
321
321
settings_table.insert(schema, rv);
325
rv = new SimpleSettings(schema, false);
325
rv = new FilteredSettings(schema, false);
531
534
"type", Secret.SchemaAttributeType.STRING);
537
public bool ensure_directory_exists(string path)
539
var gfile = File.new_for_path(path);
541
if (gfile.make_directory_with_parents())
544
catch (IOError.EXISTS e) {
545
return true; // ignore
548
warning("%s\n", e.message);
553
// By default, duplicity uses normal tmp folders like /tmp to store its
554
// in-process files. These can get quite large, especially when restoring.
555
// You may need up to twice the size of the largest source file.
556
// Because /tmp may not be super large, especially on systems that use
557
// tmpfs by default (e.g. Fedora 18), we try to use a tempdir that is on
558
// the same partition as the source files.
559
public async string get_tempdir()
561
var tempdirs = get_tempdirs();
563
// First, decide the "main include". Assume that if $HOME
564
// is present, that is it. Else, the first include we find decides it.
565
// This is admittedly fast and loose, but our primary concern is just
566
// avoiding silly choices like tmpfs or tiny special /tmp partitions.
567
var settings = get_settings();
568
var include_list = settings.get_file_list(INCLUDE_LIST_KEY);
569
File main_include = null;
570
var home = File.new_for_path(Environment.get_home_dir());
571
foreach (var include in include_list) {
572
if (include.equal(home)) {
573
main_include = include;
576
else if (main_include == null)
577
main_include = include;
579
if (main_include == null)
582
// Grab that include's fs ID
583
string filesystem_id;
585
var info = yield main_include.query_info_async(FileAttribute.ID_FILESYSTEM,
586
FileQueryInfoFlags.NONE);
587
filesystem_id = info.get_attribute_string(FileAttribute.ID_FILESYSTEM);
593
// Then, see which of our possible tempdirs matches that partition.
594
foreach (var tempdir in tempdirs) {
596
ensure_directory_exists(tempdir);
598
var gfile = File.new_for_path(tempdir);
599
var info = yield gfile.query_info_async(FileAttribute.ID_FILESYSTEM,
600
FileQueryInfoFlags.NONE);
601
temp_id = info.get_attribute_string(FileAttribute.ID_FILESYSTEM);
606
if (temp_id == filesystem_id)
610
// Fallback to simply using the highest preferred tempdir
614
public string[] get_tempdirs()
616
var tempdir = Environment.get_variable("DEJA_DUP_TEMPDIR");
617
if (tempdir != null && tempdir != "")
619
// Prefer directories that have their own cleanup logic in case ours isn't
620
// run for a while. (e.g. /tmp every boot, /var/tmp every now and then)
621
return {Environment.get_tmp_dir(), "/var/tmp",
622
Path.build_filename(Environment.get_user_cache_dir(), Config.PACKAGE,
626
public async void clean_tempdirs()
628
var tempdirs = get_tempdirs();
629
const int NUM_ENUMERATED = 16;
630
foreach (var tempdir in tempdirs) {
631
var gfile = File.new_for_path(tempdir);
633
// Now try to find and delete all files that start with "duplicity-"
635
var enumerator = yield gfile.enumerate_children_async(
636
FileAttribute.STANDARD_NAME,
637
FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
638
Priority.DEFAULT, null);
640
var infos = yield enumerator.next_files_async(NUM_ENUMERATED,
641
Priority.DEFAULT, null);
642
foreach (FileInfo info in infos) {
643
if (info.get_name().has_prefix("duplicity-")) {
644
var child = gfile.get_child(info.get_name());
645
yield new DejaDup.RecursiveDelete(child).start_async();
648
if (infos.length() != NUM_ENUMERATED)
534
658
} // end namespace