Skip to content

Commit

Permalink
Add file path prefix check to rest of local_mode.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-pratt committed Jan 22, 2025
1 parent ab58a84 commit 0e425c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions openc3/python/openc3/utilities/local_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,22 @@ def open_local_file(cls, path, scope):
def save_tool_config(cls, scope, tool, name, data):
json_data = json.loads(data)
config_path = f"{cls.LOCAL_MODE_PATH}/{scope}/tool_config/{tool}/{name}.json"
os.makedirs(os.path.dirname(config_path), exist_ok=True)
with open(config_path, "w") as file:
file.write(json.dumps(json_data, indent=2))
if os.path.normpath(config_path).startswith(cls.LOCAL_MODE_PATH):
os.makedirs(os.path.dirname(config_path), exist_ok=True)
with open(config_path, "w") as file:
file.write(json.dumps(json_data, indent=2))

@classmethod
def delete_tool_config(cls, scope, tool, name):
os.remove(f"{cls.LOCAL_MODE_PATH}/{scope}/tool_config/{tool}/{name}.json")
config_path = f"{cls.LOCAL_MODE_PATH}/{scope}/tool_config/{tool}/{name}.json"
if os.path.normpath(config_path).startswith(cls.LOCAL_MODE_PATH):
os.remove(config_path)

@classmethod
def save_setting(cls, scope, name, data):
config_path = f"{cls.LOCAL_MODE_PATH}/{scope}/settings/{name}.json"
os.makedirs(os.path.dirname(config_path), exist_ok=True)
# Anything can be stored as a setting so write it out directly
with open(config_path, "w") as file:
file.write(str(data))
if os.path.normpath(config_path).startswith(cls.LOCAL_MODE_PATH):
os.makedirs(os.path.dirname(config_path), exist_ok=True)
# Anything can be stored as a setting so write it out directly
with open(config_path, "w") as file:
file.write(str(data))

0 comments on commit 0e425c4

Please sign in to comment.