summaryrefslogtreecommitdiff
path: root/src/util/file.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/file.vala')
-rw-r--r--src/util/file.vala26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/util/file.vala b/src/util/file.vala
index c1ee06d..652a141 100644
--- a/src/util/file.vala
+++ b/src/util/file.vala
@@ -31,9 +31,11 @@ public bool claim_file(File file) throws Error {
// same or similar as what has been requested (adds numerals to the end of the name until a unique
// one has been found). The file may exist when this function returns, and it should be
// overwritten. It does *not* attempt to create the parent directory, however.
+// The used parameter allows you to pass in a collection of names which should be deemed to be
+// already claimed but which may not yet exist in the file system.
//
// This function is thread-safe.
-public File? generate_unique_file(File dir, string basename, out bool collision) throws Error {
+public File? generate_unique_file(File dir, string basename, out bool collision, Gee.Collection<string>? used = null) throws Error {
// create the file to atomically "claim" it
File file = dir.get_child(basename);
if (claim_file(file)) {
@@ -51,7 +53,9 @@ public File? generate_unique_file(File dir, string basename, out bool collision)
// generate a unique filename
for (int ctr = 1; ctr < int.MAX; ctr++) {
string new_name = (ext != null) ? "%s_%d.%s".printf(name, ctr, ext) : "%s_%d".printf(name, ctr);
-
+ if (used != null && used.contains(new_name)) {
+ continue;
+ }
file = dir.get_child(new_name);
if (claim_file(file))
return file;
@@ -151,11 +155,11 @@ public void delete_all_files(File dir, Gee.Set<string>? exceptions = null, Progr
}
}
-public time_t query_file_modified(File file) throws Error {
+public DateTime query_file_modified(File file) throws Error {
FileInfo info = file.query_info(FileAttribute.TIME_MODIFIED, FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null);
- return info.get_modification_time().tv_sec;
+ return info.get_modification_date_time();
}
public bool query_is_directory(File file) {
@@ -199,20 +203,6 @@ public string? get_file_info_id(FileInfo info) {
return info.get_attribute_string(FileAttribute.ID_FILE);
}
-// Breaks a uint64 skip amount into several smaller skips.
-public void skip_uint64(InputStream input, uint64 skip_amount) throws GLib.Error {
- while (skip_amount > 0) {
- // skip() throws an error if the amount is too large, so check against ssize_t.MAX
- if (skip_amount >= ssize_t.MAX) {
- input.skip(ssize_t.MAX);
- skip_amount -= ssize_t.MAX;
- } else {
- input.skip((size_t) skip_amount);
- skip_amount = 0;
- }
- }
-}
-
// Returns the number of files (and/or directories) within a directory.
public uint64 count_files_in_directory(File dir) throws GLib.Error {
if (!query_is_directory(dir))