save cache options in pamac.conf

This commit is contained in:
guinux 2017-09-22 11:03:37 +02:00
parent 9d138d0447
commit 20e42b6a75
10 changed files with 111 additions and 9 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ src/*.c
src/pamac.h
src/pamac.vapi
src/libpamac.so
src/pamac-clean-cache
src/pamac-user-daemon
src/pamac-system-daemon
src/pamac-tray

View File

@ -28,6 +28,7 @@ install: install_pamac-tray-appindicator
install -Dm644 src/pamac.h $(includedir)/pamac.h
install -Dm644 src/pamac.vapi $(datadir)/vala/vapi/pamac.vapi
install -Dm755 src/libpamac.so $(libdir)/libpamac.so
install -Dm755 src/pamac-clean-cache $(bindir)/pamac-clean-cache
install -Dm755 src/pamac-user-daemon $(bindir)/pamac-user-daemon
install -Dm744 src/pamac-system-daemon $(bindir)/pamac-system-daemon
install -Dm755 src/pamac-tray $(bindir)/pamac-tray
@ -66,6 +67,7 @@ uninstall:
rm -f $(includedir)/pamac.h
rm -f $(datadir)/vala/vapi/pamac.vapi
rm -f $(libdir)/libpamac.so
rm -f $(bindir)/pamac-clean-cache
rm -f $(bindir)/pamac-user-daemon
rm -f $(bindir)/pamac-system-daemon
rm -f $(bindir)/pamac-tray

View File

@ -18,3 +18,9 @@ RefreshPeriod = 6
## AUR build directory:
BuildDirectory = /tmp
## Number of versions of each package to keep in the cache:
KeepNumPackages = 3
## Remove only the versions of uninstalled packages when clean cache:
#OnlyRmUninstalled

View File

@ -3,4 +3,4 @@ Description=Clean packages cache
[Service]
Type=oneshot
ExecStart=/usr/bin/paccache -r
ExecStart=/usr/bin/pamac-clean-cache

View File

@ -39,11 +39,18 @@ MANAGER_GRESOURCE_FILE = ../resources/pamac.manager.gresource.xml
INSTALLER_GRESOURCE_FILE = ../resources/pamac.installer.gresource.xml
binaries: pamac-user-daemon pamac-system-daemon pamac-tray pamac-manager pamac-install
binaries: pamac-clean-cache pamac-user-daemon pamac-system-daemon pamac-tray pamac-manager pamac-install
clean:
rm -f *.c pamac.h pamac.vapi libpamac.so pamac-user-daemon pamac-system-daemon pamac-tray pamac-tray-appindicator pamac-manager pamac-install
pamac-clean-cache: pamac_config.vala clean_cache.vala
valac -o pamac-clean-cache \
$(COMMON_VALA_FLAGS) \
--pkg=gio-2.0 \
pamac_config.vala \
clean_cache.vala
pamac-tray: $(COMMON_SOURCES) alpm_config.vala tray.vala tray-gtk.vala
valac -o pamac-tray \
$(COMMON_VALA_FLAGS) \

32
src/clean_cache.vala Normal file
View File

@ -0,0 +1,32 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a get of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int main () {
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
string rm_only_uninstalled_str = "";
if (pamac_config.rm_only_uninstalled) {
rm_only_uninstalled_str = "-u";
}
try {
Process.spawn_command_line_sync ("paccache -q --nocolor %s -r -k %llu".printf (rm_only_uninstalled_str, pamac_config.keep_num_pkgs));
} catch (SpawnError e) {
stderr.printf ("SpawnError: %s\n", e.message);
}
return 0;
}

View File

@ -28,6 +28,8 @@ namespace Pamac {
public bool enable_aur { get; private set; }
public string aur_build_dir { get; private set; }
public bool check_aur_updates { get; private set; }
public uint64 keep_num_pkgs { get; private set; }
public bool rm_only_uninstalled { get; private set; }
public unowned HashTable<string,string> environment_variables {
get {
return _environment_variables;
@ -72,6 +74,8 @@ namespace Pamac {
enable_aur = false;
aur_build_dir = "/tmp";
check_aur_updates = false;
keep_num_pkgs = 3;
rm_only_uninstalled = false;
parse_file (conf_path);
}
@ -103,6 +107,13 @@ namespace Pamac {
unowned string val = splitted[1]._strip ();
refresh_period = uint64.parse (val);
}
} else if (key == "KeepNumPackages") {
if (splitted.length == 2) {
unowned string val = splitted[1]._strip ();
keep_num_pkgs = uint64.parse (val);
}
} else if (key == "OnlyRmUninstalled") {
rm_only_uninstalled = true;
} else if (key == "NoUpdateHideIcon") {
no_update_hide_icon = true;
} else if (key == "EnableAUR") {
@ -157,6 +168,24 @@ namespace Pamac {
} else {
data.append (line + "\n");
}
} else if (line.contains ("KeepNumPackages")) {
if (new_conf.lookup_extended ("KeepNumPackages", null, out variant)) {
data.append ("KeepNumPackages = %llu\n".printf (variant.get_uint64 ()));
new_conf.remove ("KeepNumPackages");
} else {
data.append (line + "\n");
}
} else if (line.contains ("OnlyRmUninstalled")) {
if (new_conf.lookup_extended ("OnlyRmUninstalled", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("OnlyRmUninstalled\n");
} else {
data.append ("#OnlyRmUninstalled\n");
}
new_conf.remove ("OnlyRmUninstalled");
} else {
data.append (line + "\n");
}
} else if (line.contains ("NoUpdateHideIcon")) {
if (new_conf.lookup_extended ("NoUpdateHideIcon", null, out variant)) {
if (variant.get_boolean ()) {
@ -224,6 +253,14 @@ namespace Pamac {
}
} else if (key == "RefreshPeriod") {
data.append ("RefreshPeriod = %llu\n".printf (val.get_uint64 ()));
} else if (key == "KeepNumPackages") {
data.append ("KeepNumPackages = %llu\n".printf (val.get_uint64 ()));
} else if (key == "OnlyRmUninstalled") {
if (val.get_boolean ()) {
data.append ("OnlyRmUninstalled\n");
} else {
data.append ("#OnlyRmUninstalled\n");
}
} else if (key =="NoUpdateHideIcon") {
if (val.get_boolean ()) {
data.append ("NoUpdateHideIcon\n");

View File

@ -91,6 +91,8 @@ namespace Pamac {
previous_refresh_period = transaction.refresh_period;
}
no_update_hide_icon_checkbutton.active = transaction.no_update_hide_icon;
cache_keep_nb_spin_button.value = transaction.keep_num_pkgs;
cache_only_uninstalled_checkbutton.active = transaction.rm_only_uninstalled;
// populate ignorepkgs_liststore
ignorepkgs_liststore = new Gtk.ListStore (1, typeof (string));
@ -104,6 +106,8 @@ namespace Pamac {
check_updates_button.state_set.connect (on_check_updates_button_state_set);
refresh_period_spin_button.value_changed.connect (on_refresh_period_spin_button_value_changed);
no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
cache_keep_nb_spin_button.value_changed.connect (on_cache_keep_nb_spin_button_value_changed);
cache_only_uninstalled_checkbutton.toggled.connect (on_cache_only_uninstalled_checkbutton_toggled);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
AlpmPackage pkg = transaction.find_installed_satisfier ("pacman-mirrors");
@ -181,6 +185,18 @@ namespace Pamac {
transaction.start_write_pamac_config (new_pamac_conf);
}
void on_cache_keep_nb_spin_button_value_changed () {
var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
new_pamac_conf.insert ("KeepNumPackages", new Variant.uint64 (cache_keep_nb_spin_button.get_value_as_int ()));
transaction.start_write_pamac_config (new_pamac_conf);
}
void on_cache_only_uninstalled_checkbutton_toggled () {
var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
new_pamac_conf.insert ("OnlyRmUninstalled", new Variant.boolean (cache_only_uninstalled_checkbutton.active));
transaction.start_write_pamac_config (new_pamac_conf);
}
void on_no_update_hide_icon_checkbutton_toggled () {
var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
new_pamac_conf.insert ("NoUpdateHideIcon", new Variant.boolean (no_update_hide_icon_checkbutton.active));
@ -365,8 +381,7 @@ namespace Pamac {
[GtkCallback]
void on_cache_clean_button_clicked () {
transaction.clean_cache ((uint) cache_keep_nb_spin_button.get_value_as_int (),
cache_only_uninstalled_checkbutton.active);
transaction.clean_cache (transaction.keep_num_pkgs, transaction.rm_only_uninstalled);
}
}
}

View File

@ -397,12 +397,12 @@ namespace Pamac {
});
}
public void clean_cache (uint keep_nb, bool only_uninstalled, GLib.BusName sender) {
public void clean_cache (uint64 keep_nb, bool only_uninstalled, GLib.BusName sender) {
check_authorization.begin (sender, (obj, res) => {
bool authorized = check_authorization.end (res);
if (authorized) {
string[] commands = {"paccache", "-rq"};
commands += "-k%u".printf (keep_nb);
string[] commands = {"paccache", "--nocolor", "-rq"};
commands += "-k%llu".printf (keep_nb);
if (only_uninstalled) {
commands += "-u";
}

View File

@ -63,7 +63,7 @@ namespace Pamac {
public abstract void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) throws IOError;
public abstract void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) throws IOError;
public abstract void start_generate_mirrors_list () throws IOError;
public abstract void clean_cache (uint keep_nb, bool only_uninstalled) throws IOError;
public abstract void clean_cache (uint64 keep_nb, bool only_uninstalled) throws IOError;
public abstract void start_set_pkgreason (string pkgname, uint reason) throws IOError;
public abstract void start_refresh (bool force) throws IOError;
public abstract void start_sysupgrade_prepare (bool enable_downgrade, string[] temporary_ignorepkgs) throws IOError;
@ -121,6 +121,8 @@ namespace Pamac {
public bool recurse { get { return pamac_config.recurse; } }
public uint64 refresh_period { get { return pamac_config.refresh_period; } }
public string aur_build_dir { get { return pamac_config.aur_build_dir; } }
public uint64 keep_num_pkgs { get { return pamac_config.keep_num_pkgs; } }
public bool rm_only_uninstalled { get { return pamac_config.rm_only_uninstalled; } }
//Alpm.TransFlag
int flags;
@ -448,7 +450,7 @@ namespace Pamac {
}
}
public void clean_cache (uint keep_nb, bool only_uninstalled) {
public void clean_cache (uint64 keep_nb, bool only_uninstalled) {
try {
system_daemon.clean_cache (keep_nb, only_uninstalled);
} catch (IOError e) {