-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
39 lines (36 loc) · 975 Bytes
/
test.py
File metadata and controls
39 lines (36 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import shutil
import subprocess
import sys
import time
from pathlib import Path
db_path = Path("data.db")
backup_path = Path("data.db.bak")
try:
shutil.copy(db_path, backup_path)
except:
sys.exit(1)
try:
with open(db_path, "wb") as db:
db.write(b"")
subprocess.run(["diesel", "migration", "run"])
fs_daemon = subprocess.Popen(
["target/debug/comic-fs", "mnt"],
env={"RUST_BACKTRACE": "1", "RUST_LOG": "debug"},
)
time.sleep(3)
path = Path("mnt/comics/my-comic/ep1/001.jpg")
path.parent.mkdir(parents=True, exist_ok=True)
with open(path, "wb") as f:
f.write(b"123")
with open(path, "rb") as f:
assert f.read() == b"123"
with open(path, "wb") as f:
f.write(b"456")
with open(path, "rb") as f:
assert f.read() == b"456"
except Exception as e:
print(e)
sys.exit(1)
finally:
subprocess.run(["fusermount", "-u", "mnt"])
shutil.move(backup_path, db_path)