X-Git-Url: http://dolda2000.com/gitweb/?p=tpkg.git;a=blobdiff_plain;f=tpkg;h=319d2482b831d51c8ef2a921863dedcc4904e053;hp=140ed2f4fe182e6387c5447e9c5d70f8419dcba5;hb=HEAD;hpb=82bfc891550525b31563adfca69115586ed19540 diff --git a/tpkg b/tpkg index 140ed2f..01cf38e 100755 --- a/tpkg +++ b/tpkg @@ -69,7 +69,7 @@ class prefix(object): def env(self): if self._env is None: if not os.path.isdir(self.envdir): - sys.stderr.write("tpkg: creatings %s...\n" % (self.envdir)) + sys.stderr.write("tpkg: creating %s...\n" % (self.envdir)) os.makedirs(self.envdir) env = bd.DBEnv() env.set_lk_detect(bd.DB_LOCK_RANDOM) @@ -217,7 +217,7 @@ class vfspkg(object): def __iter__(self): def scan(lp, fp): - dpre = "" if (lp is "") else lp + "/" + dpre = "" if (lp == "") else lp + "/" for dent in os.scandir(fp): dpath = dpre + dent.name if dent.is_dir(): @@ -255,13 +255,20 @@ def install(pfx, pkg, pkgname): os.makedirs(tpdir) tmpp = tp + ".tpkg-new" sb = fl.stat() - with open(tmpp, "wb") as ofp: - os.fchmod(ofp.fileno(), sb.st_mode & 0o7777) - with fl.open() as ifp: - dig = copy(ofp, ifp) - pfx.regfile(fl.path, pkgname, dig) + try: + with open(tmpp, "wb") as ofp: + os.fchmod(ofp.fileno(), sb.st_mode & 0o7777) + with fl.open() as ifp: + dig = copy(ofp, ifp) + pfx.regfile(fl.path, pkgname, dig) + except: + try: + os.unlink(tmpp) + except FileNotFoundError: + pass + raise os.rename(tmpp, tp) - os.utime(tp, ns=(time.time(), sb.st_mtime)) + os.utime(tp, ns=(round(time.time() * 1e9), round(sb.st_mtime * 1e9))) def uninstall(pfx, pkg): for fn in pfx.pkgfiles(pkg): @@ -318,6 +325,23 @@ def cmd_uninstall(argv): uninstall(prefix.use, pkgname) cmds["uninstall"] = cmd_uninstall +def cmd_list(argv): + def usage(out): + out.write("usage: tpkg list NAME\n") + opts, args = getopt.getopt(argv, "") + if len(args) < 1: + usage(sys.stderr) + sys.exit(1) + pkgname = args[0] + try: + files = prefix.use.pkgfiles(pkgname) + except KeyError: + sys.stderr.write("tpkg: %s: no such package\n" % (pkgname)) + sys.exit(1) + for fn in files: + sys.stdout.write("%s\n" % pj(prefix.use.root, fn)) +cmds["list"] = cmd_list + def usage(file): file.write("usage:\ttpkg help\n") cmds["help"] = lambda argv: usage(sys.stdout)