Skip to content

Commit

Permalink
document: Copy using SubprocessLauncher instead of GFile API
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego-Ivan committed Aug 12, 2024
1 parent 8219314 commit 073d78d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 3 additions & 4 deletions io.github.diegoivan.pdf_metadata_editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
],
"sources" : [
{
"url" : "https://gitlab.freedesktop.org/poppler/poppler.git",
"type" : "git",
"tag" : "poppler-23.01.0",
"commit" : "4259ff0c2067d302f97d87221a442eec8e88d45c"
"url" : "https://poppler.freedesktop.org/poppler-24.08.0.tar.xz",
"type" : "archive",
"sha256" : "97453fbddf0c9a9eafa0ea45ac710d3d49bcf23a62e864585385d3c0b4403174"
}
]
},
Expand Down
14 changes: 8 additions & 6 deletions src/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,17 @@ public class PaperClip.Document : Object {
}

private async void load_document (string? password) throws Error {
message ("Copy created");
cached_file = yield create_copy_from_original ();
document = new Poppler.Document.from_gfile (cached_file, password);
}

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");
Expand All @@ -458,14 +459,15 @@ public class PaperClip.Document : Object {
string destination_file = Path.build_filename (destination_path,
"%s".printf (original_file.get_basename ()));

var copy_file = File.new_for_path (destination_file);
FileCopyFlags flags = NOFOLLOW_SYMLINKS | OVERWRITE | ALL_METADATA;

bool success = yield original_file.copy_async (copy_file, flags);
Subprocess copy_process = launcher.spawn("cp", original_file.get_path(), destination_path);
bool success = yield copy_process.wait_async ();
if (!success) {
critical ("Copy Unsuccessful");
message ("Processed failed");
}


var copy_file = File.new_for_path (destination_file);

return copy_file;
}
}
Expand Down

0 comments on commit 073d78d

Please sign in to comment.