diff options
author | Ruben Pollan <meskio@sindominio.net> | 2015-08-10 12:50:04 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2015-08-14 10:47:27 +0200 |
commit | d01f4b4cd493a762da74fb9b1d7bdb26dace4d68 (patch) | |
tree | 5d403049217d718696632e483d3d1d682f537dcc | |
parent | 6933022e17c4b7d79a4e8c1b21139b2a8d9ed434 (diff) |
[feat] delete outated files after update
For that we have ported the apply updates to python and disable the
execution in the C++. The C++ code is not removed as this updater will
be outdated after the 0.9.
- Related: #5876
-rw-r--r-- | changes/feat-5876_delete_outdated | 1 | ||||
-rw-r--r-- | src/launcher.py | 59 | ||||
-rw-r--r-- | src/main.cpp | 1 |
3 files changed, 60 insertions, 1 deletions
diff --git a/changes/feat-5876_delete_outdated b/changes/feat-5876_delete_outdated new file mode 100644 index 0000000..40e8947 --- /dev/null +++ b/changes/feat-5876_delete_outdated @@ -0,0 +1 @@ +- Delete outdated files after update diff --git a/src/launcher.py b/src/launcher.py index 77fb559..8daf790 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -1,5 +1,64 @@ +import os +import os.path +import shutil +import tuf.client.updater from leap.bitmask.app import start_app as bitmask_client +REPO_DIR = "repo/" +UPDATES_DIR = "updates/" + + +def update_if_needed(): + if not os.path.isdir(UPDATES_DIR): + print "No updates found" + return + + print "Found updates, merging directories before doing anything..." + try: + remove_obsolete() + merge_directories(UPDATES_DIR, ".") + shutil.rmtree(UPDATES_DIR) + except Exception as e: + print "An error has ocurred while updating: " + e.message + + +def remove_obsolete(): + tuf.conf.repository_directory = REPO_DIR + updater = tuf.client.updater.Updater('leap-updater', {}) + updater.remove_obsolete_targets(".") + + +def merge_directories(src, dest): + for root, dirs, files in os.walk(src): + if not os.path.exists(root): + # It was moved as the dir din't exist in dest + continue + + destroot = os.path.join(dest, root[len(src):]) + + for f in files: + srcpath = os.path.join(root, f) + destpath = os.path.join(destroot, f) + if os.path.exists(destpath): + # FIXME: On windows we can't remove, but we can rename and + # afterwards remove. is that still true with python? + # or was just something specific of our implementation + # with C++? + os.remove(destpath) + os.rename(srcpath, destpath) + + for d in dirs: + srcpath = os.path.join(root, d) + destpath = os.path.join(destroot, d) + + if os.path.exists(destpath) and not os.path.isdir(destpath): + os.remove(destpath) + + if not os.path.exists(destpath): + os.rename(srcpath, destpath) + + if __name__ == "__main__": + update_if_needed() bitmask_client() diff --git a/src/main.cpp b/src/main.cpp index e7169c2..2e6aa00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,7 +118,6 @@ main(int argc, char** argv) try { fs::path full_path(fs::system_complete(argv[0]).parent_path()); - updateIfNeeded(full_path); auto pypath = full_path.string() + "/apps/:" + full_path.string() + "/lib/"; std::cout << pypath << std::endl; #if not defined _WIN32 && not defined _WIN64 |