summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Anderson2017-12-28 12:19:06 -0600
committerEric Anderson2017-12-28 12:19:06 -0600
commit1faebce10e86ca3b6865de71ea6cdbdd625a5130 (patch)
tree49d66853608fe2c4873315d937512d9d85d5df1b
parent3666e6d34419c4859756e94d502e2068393a9108 (diff)
downloadaur-1faebce10e86ca3b6865de71ea6cdbdd625a5130.tar.gz
Bump to 0.4.6 for canonical cache location
Instead of searching for the cache, just expect it to be stored in a well-known location. This also avoids loading a cache created by a different user, which is a security improvement.
-rw-r--r--.SRCINFO7
-rw-r--r--PKGBUILD6
-rwxr-xr-xpkgdistcache-client42
3 files changed, 28 insertions, 27 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 1bbfaf8e5b8a..f06bab1851bf 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,8 +1,8 @@
# Generated by mksrcinfo v8
-# Wed Dec 27 23:37:36 UTC 2017
+# Thu Dec 28 18:17:16 UTC 2017
pkgbase = pkgdistcache
pkgdesc = A distributed local-network cache for pacman packages
- pkgver = 0.4.5
+ pkgver = 0.4.6
pkgrel = 1
url = http://venator.ath.cx/dw/doku.php?id=linux:pkgdistcache
install = pkgdistcache.install
@@ -14,11 +14,12 @@ pkgbase = pkgdistcache
depends = python-gobject
depends = curl
depends = python-requests
+ depends = python-xdg
source = pkgdistcache-client
source = pkgdistcache-daemon
source = pkgdistcache.conf
source = pkgdistcached.service
- sha256sums = 86303871992738372d6ea5d11c3e75a7b894d5ebff1018fdbf213f393fc42be8
+ sha256sums = c1d9df5a1e37dde556ba47f1262d19a61fff57fbd7e1a0e370b9e671802e343c
sha256sums = 8f298c9f1548b56373038fe69f8568dc77e17a700476594155359df20eb275a4
sha256sums = d77ac418aa651bc622cd91204d6907554c6cdb4bb989e484cc54da32342faa51
sha256sums = 756c0bd1139e296da88937a89ab19e0b5d6c0d5d0f719034d4029b1fe1ea09e9
diff --git a/PKGBUILD b/PKGBUILD
index 1a42f8215cdb..4a7175cc4485 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -2,19 +2,19 @@
# Maintainer: Eric Anderson <ejona86@gmail.com>
pkgname=pkgdistcache
-pkgver=0.4.5
+pkgver=0.4.6
pkgrel=1
pkgdesc='A distributed local-network cache for pacman packages'
arch=('any')
url='http://venator.ath.cx/dw/doku.php?id=linux:pkgdistcache'
license=('GPL')
-depends=('avahi' 'python-dbus' 'dbus-glib' 'python-gobject' 'curl' 'python-requests')
+depends=('avahi' 'python-dbus' 'dbus-glib' 'python-gobject' 'curl' 'python-requests' 'python-xdg')
install="${pkgname}.install"
source=('pkgdistcache-client'
'pkgdistcache-daemon'
'pkgdistcache.conf'
'pkgdistcached.service')
-sha256sums=('86303871992738372d6ea5d11c3e75a7b894d5ebff1018fdbf213f393fc42be8'
+sha256sums=('c1d9df5a1e37dde556ba47f1262d19a61fff57fbd7e1a0e370b9e671802e343c'
'8f298c9f1548b56373038fe69f8568dc77e17a700476594155359df20eb275a4'
'd77ac418aa651bc622cd91204d6907554c6cdb4bb989e484cc54da32342faa51'
'756c0bd1139e296da88937a89ab19e0b5d6c0d5d0f719034d4029b1fe1ea09e9')
diff --git a/pkgdistcache-client b/pkgdistcache-client
index 7ad821bf7b69..f120f820e335 100755
--- a/pkgdistcache-client
+++ b/pkgdistcache-client
@@ -16,6 +16,8 @@ from gi.repository import GObject as gobject
import dbus.glib
import pickle
import requests
+import time
+import xdg.BaseDirectory
colors = {'none': '\033[0m',
'black': '\033[0;30m', 'bold_black': '\033[1;30m',
@@ -36,12 +38,6 @@ def printerr(msg):
def printwarn(msg):
print("%s!! %s%s" % (colors['bold_yellow'], msg, colors['none']))
-# Run a command synchronously, redirecting stdout and stderr to strings
-def runcmd(cmd, cwd=None):
- pipe = subprocess.Popen(cmd, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdout, stderr) = pipe.communicate() # wait for process to terminate and return stdout and stderr
- return {'stdout': stdout.strip(), 'stderr': stderr.strip(), 'retcode': pipe.returncode}
-
# Run a command synchronously, sending stdout and stderr to shell
def runcmd2(cmd, cwd=None):
pipe = subprocess.Popen(cmd, shell=True, cwd=cwd, stdout=None, stderr=None)
@@ -125,27 +121,31 @@ def main(argv):
must_download = True
if not (pkg.endswith('.db') or pkg.endswith('.db.sig')):
- # find first /tmp/pkgdistcache.* file modified less than CACHE_FILE_LIFE minutes ago
- cmd = 'find /tmp -name "pkgdistcache.*" -mmin -' + str(config['cache_file_life'])
- cache_file = runcmd(cmd)['stdout']
- if len(cache_file) > 0:
- # recent cache file found, use it
+ runtime_dir = xdg.BaseDirectory.get_runtime_dir(strict=False)
+ cache_file = os.path.join(runtime_dir, 'pkgdistcache')
+ try:
+ # No exception means file exists
+ stat = os.stat(cache_file)
+ # Check age of file
+ cache_life_secs = int(config['cache_file_life']) * 60
+ cache_valid = time.time() < stat.st_mtime + cache_life_secs
+ except FileNotFoundError:
+ cache_valid = False
+ if cache_valid:
with open(cache_file, 'rb') as f:
pkgdistcache_clients = pickle.load(f)
else:
- # recent cache file not found, discover other pkgdistcache capable hosts via avahi and save result to a new cache file
- runcmd("rm -f /tmp/pkgdistcache.*") # remove any old cache file
- cache_file = runcmd('mktemp /tmp/pkgdistcache.XXXXX')['stdout'] # create new cache file
-
- hostname = runcmd('hostname')['stdout']
+ # recent cache file not found, discover other pkgdistcache capable
+ # hosts via avahi and save result to a new cache file
browser = AvahiBrowser()
clients = browser.browse("_pkgdistcache._tcp")
clients = set(clients) # remove duplicates (eg services offered on more than a network card etc.)
- pkgdistcache_clients = []
- for client in clients:
- if client.host != hostname: # exclude current machine from results
- pkgdistcache_clients.append(client)
-
+ pkgdistcache_clients = list(clients)
+
+ try:
+ os.unlink(cache_file) # remove any old cache file
+ except FileNotFoundError:
+ pass
with open(cache_file, 'wb') as f:
pickle.dump(pkgdistcache_clients, f, -1)