add check if mountpoint exists
This commit is contained in:
parent
723ed0a433
commit
935ac75f6c
1 changed files with 19 additions and 5 deletions
24
workdirfs.py
24
workdirfs.py
|
@ -16,6 +16,9 @@ import shutil
|
||||||
import json
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -308,11 +311,22 @@ def main(args):
|
||||||
if mountpoint.is_symlink():
|
if mountpoint.is_symlink():
|
||||||
mountpoint.unlink();
|
mountpoint.unlink();
|
||||||
if mountpoint.exists():
|
if mountpoint.exists():
|
||||||
mountpoint.rename(mountpoint + datetime.now().strftime("%Y-%m-%d")
|
if mountpoint.is_dir():
|
||||||
+ ''.join(random.choice(
|
if os.listdir(mountpoint):
|
||||||
string.ascii_uppercase + string.digits) for _ in range(6))
|
mountpoint.rename(str(mountpoint) + "-" + datetime.now().strftime("%Y-%m-%d")
|
||||||
+ ".bak")
|
+ "-"
|
||||||
mountpoint.mkdir()
|
+ ''.join(random.choice(
|
||||||
|
string.ascii_uppercase + string.digits) for _ in range(6))
|
||||||
|
+ ".bak")
|
||||||
|
else:
|
||||||
|
mountpoint.rename(str(mountpoint) + "-" + datetime.now().strftime("%Y-%m-%d")
|
||||||
|
+ "-"
|
||||||
|
+ ''.join(random.choice(
|
||||||
|
string.ascii_uppercase + string.digits) for _ in range(6))
|
||||||
|
+ ".bak")
|
||||||
|
|
||||||
|
mountpoint.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
|
|
||||||
# if not (os.path.isdir(mountpoint) or os.path.exists(mountpoint)):
|
# if not (os.path.isdir(mountpoint) or os.path.exists(mountpoint)):
|
||||||
# if Path(mountpoint).is_symlink():
|
# if Path(mountpoint).is_symlink():
|
||||||
# os.path.remove
|
# os.path.remove
|
||||||
|
|
Loading…
Reference in a new issue