Compare commits
24 Commits
v0.1.0
...
folder_res
| Author | SHA1 | Date | |
|---|---|---|---|
| dfcffb19e4 | |||
| b221fa3534 | |||
| a24cc8f2b9 | |||
|
|
d7330933bc | ||
| ac32bae975 | |||
|
|
b181e31a0c | ||
| 4fd1243472 | |||
|
|
328eeaca7a | ||
| 19b79b26ff | |||
|
|
a67e31c65d | ||
| 9d4608bd34 | |||
|
|
27468ae0d0 | ||
| 8b1d9a81a1 | |||
| 6eb3f5a210 | |||
|
|
9a64bef661 | ||
| 5b46a3af01 | |||
|
|
c8cc694e3c | ||
| 756a6af4ac | |||
| a20bbeb9f8 | |||
| 668d6bbba4 | |||
| 62264ea115 | |||
| d38ec538a4 | |||
| 166f2dfac2 | |||
| ac284d29e3 |
@@ -17,17 +17,20 @@ It moves files to a per-user _trash_ instead of permanently deleting them, while
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install via Poetry:
|
**NOTE:** To use `resrm` with `sudo`, the path to `resrm` must be in the `$PATH` seen by `root`.\
|
||||||
|
Either install `resrm` as `root` (_preferred_), use `sudo -E resrm`, or add the `$PATH` to `/etc/sudoers` using its `Defaults secure_path` parameter.
|
||||||
|
|
||||||
|
Install via PyPI (_preferred_):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
poetry add resrm
|
pip install resrm
|
||||||
```
|
```
|
||||||
|
|
||||||
Or clone the repo and install locally:
|
Or clone the repo and install locally:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/mdaleo404/resrm.git
|
git clone https://github.com/mdaleo404/resrm.git
|
||||||
cd resrm
|
cd resrm/resrm
|
||||||
poetry install
|
poetry install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
0
resrm/poetry.lock → poetry.lock
generated
0
resrm/poetry.lock → poetry.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "resrm"
|
name = "resrm"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = "drop-in replacement for rm with undo/restore built-in."
|
description = "drop-in replacement for rm with undo/restore built-in."
|
||||||
authors = ["Marco D'Aleo <marco@marcodaleo.com>"]
|
authors = ["Marco D'Aleo <marco@marcodaleo.com>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
# resrm
|
|
||||||
|
|
||||||
**resrm** is a safe, drop-in replacement for the Linux `rm` command with **undo/restore support**.
|
|
||||||
It moves files to a per-user _trash_ instead of permanently deleting them, while still allowing full `sudo` support for root-owned files.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Move files and directories to a **trash folder** instead of permanent deletion
|
|
||||||
- Restore deleted files by **short ID or exact basename**
|
|
||||||
- Empty trash safely
|
|
||||||
- Supports `-r`, `-f`, `-i`, `--perma` options
|
|
||||||
- Works with `sudo` for root-owned files
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
Install via Poetry:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
poetry add resrm
|
|
||||||
```
|
|
||||||
|
|
||||||
Or clone the repo and install locally:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/mdaleo404/resrm.git
|
|
||||||
cd resrm
|
|
||||||
poetry install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Move files to trash
|
|
||||||
resrm file1 file2
|
|
||||||
|
|
||||||
# Recursive remove of a directory
|
|
||||||
resrm -r mydir
|
|
||||||
|
|
||||||
# Force remove (ignore nonexistent)
|
|
||||||
resrm -f file
|
|
||||||
|
|
||||||
# Interactive remove
|
|
||||||
resrm -i file
|
|
||||||
|
|
||||||
# Permanent delete (bypass trash)
|
|
||||||
resrm --perma file
|
|
||||||
|
|
||||||
# List trash entries
|
|
||||||
resrm -l
|
|
||||||
|
|
||||||
# Restore a file by ID or basename
|
|
||||||
resrm --restore <id|name>
|
|
||||||
|
|
||||||
# Empty the trash permanently
|
|
||||||
resrm --empty
|
|
||||||
```
|
|
||||||
|
|
||||||
## Trash Location
|
|
||||||
|
|
||||||
Normal users: `~/.local/share/resrm/files`
|
|
||||||
|
|
||||||
Root user: `/root/.local/share/resrm/files`
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -116,6 +116,41 @@ def find_candidates(identifier: str) -> List[Dict]:
|
|||||||
if id_matches:
|
if id_matches:
|
||||||
return id_matches
|
return id_matches
|
||||||
|
|
||||||
|
def restore_many(identifiers: List[str]):
|
||||||
|
"""Restore multiple files, prompting when needed."""
|
||||||
|
for identifier in identifiers:
|
||||||
|
candidates = find_candidates(identifier)
|
||||||
|
|
||||||
|
if not candidates:
|
||||||
|
print(f"No match found for '{identifier}'")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Only one match - restore immediately
|
||||||
|
if len(candidates) == 1:
|
||||||
|
restore_one(candidates[0])
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Multiple matches - prompt user
|
||||||
|
print(f"Multiple matches for '{identifier}':")
|
||||||
|
for i, entry in enumerate(candidates, start=1):
|
||||||
|
print(f"{i}) {short_id(entry['id'])} {entry['orig_path']} ({entry['timestamp']})")
|
||||||
|
|
||||||
|
try:
|
||||||
|
choice = input("Choose number to restore (or skip): ").strip()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nAborted.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not choice.isdigit():
|
||||||
|
print("Skipped.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
idx = int(choice) - 1
|
||||||
|
if 0 <= idx < len(candidates):
|
||||||
|
restore_one(candidates[idx])
|
||||||
|
else:
|
||||||
|
print("Invalid selection. Skipped.")
|
||||||
|
|
||||||
def restore_one(entry: Dict) -> bool:
|
def restore_one(entry: Dict) -> bool:
|
||||||
src = TRASH_DIR / entry["id"]
|
src = TRASH_DIR / entry["id"]
|
||||||
dest = Path(entry["orig_path"])
|
dest = Path(entry["orig_path"])
|
||||||
@@ -209,7 +244,7 @@ def move_to_trash(path: Path, interactive: bool, force: bool, recursive: bool, p
|
|||||||
print(f"Failed permanent delete: {e}")
|
print(f"Failed permanent delete: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 🚫 Prevent non-root user deleting root-owned files
|
# Prevent non-root user deleting root-owned files
|
||||||
try:
|
try:
|
||||||
st = path.stat()
|
st = path.stat()
|
||||||
if st.st_uid == 0 and os.geteuid() != 0:
|
if st.st_uid == 0 and os.geteuid() != 0:
|
||||||
@@ -218,7 +253,7 @@ def move_to_trash(path: Path, interactive: bool, force: bool, recursive: bool, p
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 🧭 Detect which trash to use (based on file owner)
|
# Detect which trash to use (based on file owner)
|
||||||
try:
|
try:
|
||||||
import pwd
|
import pwd
|
||||||
owner_uid = path.stat().st_uid
|
owner_uid = path.stat().st_uid
|
||||||
@@ -273,7 +308,7 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
parser.add_argument("-f", action="store_true", help="force")
|
parser.add_argument("-f", action="store_true", help="force")
|
||||||
parser.add_argument("-i", action="store_true", help="interactive")
|
parser.add_argument("-i", action="store_true", help="interactive")
|
||||||
parser.add_argument("--perma", action="store_true", help="permanent delete")
|
parser.add_argument("--perma", action="store_true", help="permanent delete")
|
||||||
parser.add_argument("--restore", nargs=1, help="restore by id or basename")
|
parser.add_argument("--restore", nargs="+", help="restore by id or basename")
|
||||||
parser.add_argument("-l", action="store_true", help="list trash")
|
parser.add_argument("-l", action="store_true", help="list trash")
|
||||||
parser.add_argument("--empty", action="store_true", help="empty the trash permanently")
|
parser.add_argument("--empty", action="store_true", help="empty the trash permanently")
|
||||||
parser.add_argument("--help", action="store_true", help="show help")
|
parser.add_argument("--help", action="store_true", help="show help")
|
||||||
@@ -293,7 +328,7 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if args.restore:
|
if args.restore:
|
||||||
restore(args.restore[0])
|
restore_many(args.restore)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not args.paths:
|
if not args.paths:
|
||||||
Reference in New Issue
Block a user