Add fileExists to API

This commit is contained in:
Fierelier 2021-11-01 14:48:46 +01:00
parent 15d2e2c757
commit 41b08ef999

View File

@ -108,6 +108,27 @@ def removeFile(path):
"--command=delete '" +path+ "'" "--command=delete '" +path+ "'"
],check=True) ],check=True)
def fileExists(path):
if target["type"] == "offline":
return os.path.isfile(filePath(path))
# This is super super super dirty and dumb, fix this somehow
if target["type"] == "wim":
trashpath = p(tmpPath,"opus-nt_trash")
if not os.path.isdir(trashpath): os.makedirs(trashpath)
try:
subprocess.run([
"wimlib-imagex","extract",
target["path"],str(target["index"]),
path,"--dest-dir=" +trashpath,
"--preserve-dir-structure"
],check=True)
except:
subprocess.run(["rmdir","/s","/q",trashpath],check=True,shell=True)
return False
subprocess.run(["rmdir","/s","/q",trashpath],check=True,shell=True)
return True
def filePath(path): def filePath(path):
if target["type"] == "offline": return p(target["path"],path) if target["type"] == "offline": return p(target["path"],path)
if target["type"] == "wim": return p(tmpPath,path) if target["type"] == "wim": return p(tmpPath,path)