diff --git a/rdify b/rdify index d6baf32..28044b5 100755 --- a/rdify +++ b/rdify @@ -17,8 +17,9 @@ class RamDiskItem(): self.target = Path(target) self.persist = Path(persist) self.ramdisk = Path("/dev/shm/ramdisk") - self.full_rd_path = ramdisk.joinpath(target.name) - self.full_persist_path = persist.joinpath(target.name) + self.full_rd_path = self.ramdisk.joinpath(self.target.name) + self.full_persist_path = self.persist.joinpath(self.target.name) + self.rsync_destination = self.full_persist_path if self.target.is_file() else self.persist def init(self): @@ -26,7 +27,7 @@ class RamDiskItem(): self.ramdisk.mkdir(parents=True, exist_ok=True) - if target.is_file(): + if self.target.is_file(): shutil.copy2(self.target, self.ramdisk) else: shutil.copytree(self.target, self.full_rd_path) @@ -37,21 +38,28 @@ class RamDiskItem(): def sync(self): # TODO: actually look at output from this... - subprocess.run(["rsync", "-aP", "--delete", self.full_rd_path, self.full_persist_path]) + subprocess.run(["rsync", "-aP", "--delete", self.full_rd_path, self.rsync_destination]) def loop_sync(self, delay): while True: - self.sync - time.sleep(delay) + try: + self.sync() + time.sleep(delay) + except KeyboardInterrupt: + eprint("Interrupt received, exiting...") + return def cleanup(self): + if not self.target.is_symlink(): + eprint(f"Target: {self.target} isn't a symlink!") + return self.sync() + self.target.unlink() shutil.move(self.full_persist_path, self.target.parent) if self.full_rd_path.is_file(): self.full_rd_path.unlink() else: shutil.rmtree(self.full_rd_path) - shutil.rmtree(self.full_persist_path) def main(): @@ -86,7 +94,7 @@ def main(): elif args.loop_sync: rd_item.loop_sync(args.loop_sync) elif args.cleanup: - rd_item.cleanup(args.target, args.perist) + rd_item.cleanup() else: pass