Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ public class PaperClip.Document : Object {
}
}

~Document () {
try {
cached_file.delete ();
} catch (Error e) {
warning (e.message);
}
}

// This function is intended to be run from a background thread
private bool load_xmp () throws Error {
bool success = false;
Expand Down Expand Up @@ -466,29 +474,22 @@ public class PaperClip.Document : Object {
}

private async File create_copy_from_original () throws Error {
var launcher = new SubprocessLauncher (NONE);
unowned string tmp_dir = Environment.get_tmp_dir ();
string destination_path = Path.build_path (Path.DIR_SEPARATOR_S,
tmp_dir,
"copies");
int res = DirUtils.create_with_parents (destination_path, 0777);
if (res < 0) {
throw new IOError.FAILED (@"Could not create $destination_path");
}

string destination_file = Path.build_filename (destination_path,
"%s".printf (original_file.get_basename ()));
GLib.File tmp_file;
GLib.FileIOStream stream;

Subprocess copy_process = launcher.spawn("cp", original_file.get_path(), destination_path);
bool success = yield copy_process.wait_async ();
if (!success) {
critical ("Processed failed");
try {
tmp_file = GLib.File.new_tmp ("pdf-metadata-editor-XXXXXX.pdf", out stream);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use GLib.File.new_tmp_async instead.

} catch (Error e) {
throw new IOError.FAILED (@"Failed to create temporary file: %s", e.message);
}

try {
yield original_file.copy_async (tmp_file, FileCopyFlags.OVERWRITE);
} catch (Error e) {
throw new IOError.FAILED (@"Failed to copy file to temporary location: %s", e.message);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should close the stream using stream.close_async. I'm not sure if closing it before freeing it is the default behaviour, but we better be cautious :)

var copy_file = File.new_for_path (destination_file);

return copy_file;
return tmp_file;
}
}

Expand Down