Commit 9521dd09 authored by guinux's avatar guinux

various improvements

parent 5d86566d
......@@ -237,7 +237,6 @@ namespace Pamac {
i++;
}
if (targets.length == 0) {
// set pkgname to the current dir
var current_dir = File.new_for_path (Environment.get_current_dir ());
var pkgbuild = current_dir.get_child ("PKGBUILD");
if (!pkgbuild.query_exists ()) {
......@@ -245,20 +244,36 @@ namespace Pamac {
stdout.printf ("\n");
return;
}
targets += current_dir.get_basename ();
// set buildir to the parent dir
File? parent = current_dir.get_parent ();
if (parent != null) {
database.config.aur_build_dir = parent.get_path ();
}
} else if (!transaction.clone_build_files) {
string? pkgbase = current_dir.get_basename ();
if (pkgbase != null) {
// add pkgnames of srcinfo to targets
var cancellable = new Cancellable ();
database.regenerate_srcinfo.begin (pkgbase, cancellable, (obj, res) => {
bool success = database.regenerate_srcinfo.end (res);
if (success) {
foreach (unowned string pkgname in database.get_srcinfo_pkgnames (pkgbase)) {
targets += pkgname;
}
}
loop.quit ();
});
loop.run ();
}
} else if (transaction.clone_build_files) {
// check if targets exist
foreach (unowned string target in targets) {
var dir = File.new_for_path (Path.build_path ("/", database.config.aur_build_dir, target));
if (!dir.query_exists ()) {
print_error (dgettext (null, "target not found: %s").printf (target));
return;
}
bool success = true;
check_build_pkgs.begin (targets, (obj, res) => {
success = check_build_pkgs.end (res);
loop.quit ();
});
loop.run ();
if (!success) {
return;
}
}
build_pkgs (targets);
......@@ -1770,7 +1785,7 @@ namespace Pamac {
continue;
} else {
// clone build files
stdout.printf (dgettext (null, "Cloning %s build files".printf (pkgname)) + "...\n");
stdout.printf (dgettext (null, "Cloning %s build files").printf (aur_pkg_details.packagebase) + "...\n");
// use packagebase in case of split package
File? clone_dir = yield database.clone_build_files (aur_pkg_details.packagebase, overwrite);
if (clone_dir == null) {
......@@ -1809,31 +1824,24 @@ namespace Pamac {
}
}
async bool check_build_pkgs () {
var aur_pkgs = yield database.get_aur_pkgs (to_build);
async bool check_build_pkgs (string[] targets) {
var aur_pkgs = yield database.get_aur_pkgs (targets);
var iter = HashTableIter<string, AURPackage> (aur_pkgs);
unowned string pkgname;
unowned AURPackage aur_pkg;
bool success = true;
while (iter.next (out pkgname, out aur_pkg)) {
if (aur_pkg.name == "") {
print_error (dgettext (null, "target not found: %s").printf (pkgname));
return false;
success = false;
}
}
return true;
return success;
}
void build_pkgs (string[] to_build) {
this.to_build = to_build;
bool success = false;
check_build_pkgs.begin ((obj, res) => {
success = check_build_pkgs.end (res);
loop.quit ();
});
loop.run ();
if (success) {
try_lock_and_run (start_transaction);
}
try_lock_and_run (start_transaction);
}
void start_transaction () {
......
......@@ -1146,9 +1146,9 @@ namespace Pamac {
cmds = {"git", "diff", "--exit-code", "origin/master"};
FileEnumerator enumerator = yield pkgdir.enumerate_children_async ("standard::*", FileQueryInfoFlags.NONE);
FileInfo info;
// don't see .SRCINFO diff
// don't show .SRCINFO diff
while ((info = enumerator.next_file (null)) != null) {
string filename = info.get_name ();
unowned string filename = info.get_name ();
if (filename != ".SRCINFO") {
cmds += filename;
}
......@@ -1196,6 +1196,57 @@ namespace Pamac {
return null;
}
public async bool regenerate_srcinfo (string pkgname, Cancellable? cancellable = null) {
string pkgdir_name = Path.build_path ("/", config.aur_build_dir, pkgname);
var srcinfo = File.new_for_path (Path.build_path ("/", pkgdir_name, ".SRCINFO"));
var pkgbuild = File.new_for_path (Path.build_path ("/", pkgdir_name, "PKGBUILD"));
// check if PKGBUILD was modified after .SRCINFO
try {
FileInfo info = srcinfo.query_info ("time::modified", 0);
TimeVal srcinfo_time = info.get_modification_time ();
info = pkgbuild.query_info ("time::modified", 0);
TimeVal pkgbuild_time = info.get_modification_time ();
if (pkgbuild_time.tv_sec <= srcinfo_time.tv_sec) {
// no need to regenerate
return true;
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
// generate .SRCINFO
var launcher = new SubprocessLauncher (SubprocessFlags.STDOUT_PIPE);
launcher.set_cwd (pkgdir_name);
try {
Subprocess process = launcher.spawnv ({"makepkg", "--printsrcinfo"});
try {
yield process.wait_async (cancellable);
if (process.get_if_exited ()) {
if (process.get_exit_status () == 0) {
try {
var dis = new DataInputStream (process.get_stdout_pipe ());
// delete the file before rewrite it
yield srcinfo.delete_async ();
// creating a DataOutputStream to the file
var dos = new DataOutputStream (yield srcinfo.create_async (FileCreateFlags.REPLACE_DESTINATION));
// writing makepkg output to .SRCINFO
yield dos.splice_async (dis, 0);
return true;
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
}
} catch (Error e) {
// cancelled
process.send_signal (Posix.Signal.INT);
process.send_signal (Posix.Signal.KILL);
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
return false;
}
async void populate_aur_infos (string[] pkgnames) {
string[] names = {};
foreach (unowned string pkgname in pkgnames) {
......@@ -1390,6 +1441,27 @@ namespace Pamac {
return data;
}
public string[] get_srcinfo_pkgnames (string pkgdir) {
string[] pkgnames = {};
var srcinfo = File.new_for_path (Path.build_path ("/", config.aur_build_dir, pkgdir, ".SRCINFO"));
if (srcinfo.query_exists ()) {
try {
// read .SRCINFO
var dis = new DataInputStream (srcinfo.read ());
string line;
while ((line = dis.read_line ()) != null) {
if ("pkgname = " in line) {
string pkgname = line.split (" = ", 2)[1];
pkgnames += (owned) pkgname;
}
}
} catch (GLib.Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
return pkgnames;
}
public async List<AURPackage> get_aur_updates () {
// get local pkgs
string[] local_pkgs = {};
......
......@@ -506,9 +506,8 @@ namespace Pamac {
yield process.wait_async ();
if (process.get_if_exited ()) {
if (process.get_exit_status () == 0) {
// emit start_preparing to make regenerate_srcinfo cancellable
start_preparing ();
return yield regenerate_srcinfo (pkgname);
var cancellable = new Cancellable ();
return yield database.regenerate_srcinfo (pkgname, cancellable);
}
}
} catch (Error e) {
......
......@@ -265,6 +265,7 @@ namespace Pamac {
if (no_confirm_upgrade
&& must_confirm_length == 0
&& summary.to_upgrade.length () > 0) {
show_warnings (true);
return true;
}
int response = show_summary (summary);
......@@ -559,7 +560,7 @@ namespace Pamac {
// writing a string to the stream
dos.put_string (textview.buffer.get_text (start_iter, end_iter, false));
if (build_files_notebook.get_tab_label_text (child) == "PKGBUILD") {
success = yield regenerate_srcinfo (pkgname);
success = yield database.regenerate_srcinfo (pkgname);
}
} catch (GLib.Error e) {
stderr.printf("%s\n", e.message);
......
......@@ -375,6 +375,9 @@ namespace Pamac {
if (build_cancellable.is_cancelled ()) {
return;
}
if (already_checked_aur_dep.contains (pkgname)) {
continue;
}
File? clone_dir;
if (clone_build_files) {
unowned AURPackage aur_pkg = aur_pkgs.lookup (pkgname);
......@@ -384,22 +387,39 @@ namespace Pamac {
}
// clone build files
// use packagebase in case of split package
emit_action (dgettext (null, "Cloning %s build files").printf (pkgname) + "...");
emit_action (dgettext (null, "Cloning %s build files").printf (aur_pkg.packagebase) + "...");
clone_dir = yield database.clone_build_files (aur_pkg.packagebase, false);
if (clone_dir == null) {
// error
continue;
}
already_checked_aur_dep.add (aur_pkg.packagebase);
} else {
clone_dir = File.new_for_path (Path.build_path ("/", database.config.aur_build_dir, pkgname));
if (!clone_dir.query_exists ()) {
// error
// didn't find the target
// parse all builddir to be sure to find it
var builddir = File.new_for_path (database.config.aur_build_dir);
try {
FileEnumerator enumerator = yield builddir.enumerate_children_async ("standard::*", FileQueryInfoFlags.NONE);
FileInfo info;
while ((info = enumerator.next_file (null)) != null) {
unowned string filename = info.get_name ();
if (!(filename in already_checked_aur_dep)) {
dep_to_check += filename;
}
}
} catch (GLib.Error e) {
stderr.printf ("Error: %s\n", e.message);
}
continue;
}
if (!(yield regenerate_srcinfo (pkgname))) {
emit_action (dgettext (null, "Generating %s informations").printf (pkgname) + "...");
if (!(yield database.regenerate_srcinfo (pkgname, build_cancellable))) {
// error
continue;
}
already_checked_aur_dep.add (pkgname);
}
if (build_cancellable.is_cancelled ()) {
return;
......@@ -560,7 +580,6 @@ namespace Pamac {
if (pkg.name == "") {
string dep_name = database.get_alpm_dep_name (dep_string);
if (!(dep_name in already_checked_aur_dep)) {
already_checked_aur_dep.add (dep_name);
dep_to_check += (owned) dep_name;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment