Browse Source

Protect against corner case where rename happens into a subdir of the session

master
Nils 5 years ago
parent
commit
2d89051867
  1. 6
      engine/nsmservercontrol.py

6
engine/nsmservercontrol.py

@ -37,6 +37,7 @@ import subprocess
import atexit import atexit
import pathlib import pathlib
import json import json
from uuid import uuid4
from datetime import datetime from datetime import datetime
from sys import exit as sysexit from sys import exit as sysexit
@ -1363,7 +1364,10 @@ class NsmServerControl(object):
return False return False
else: else:
logger.info(f"Renaming {nsmSessionName} to {newName}.") logger.info(f"Renaming {nsmSessionName} to {newName}.")
oldPath.rename(newPath) tmp = pathlib.Path(oldPath.name+str(uuid4())) #Can't move itself into a subdir in itself. move to temp first. We don't use tempdir because that could be on another partition. we already know we can write here.
oldPath.rename(tmp)
pathlib.Path(newPath).mkdir(parents=True, exist_ok=True)
tmp.rename(newPath)
assert newPath.exists() assert newPath.exists()
def copySession(self, nsmSessionName:str, newName:str): def copySession(self, nsmSessionName:str, newName:str):

Loading…
Cancel
Save