From b1159cdbf4d1e3e9fb4f0df6bde7100a375b30e3 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 27 Oct 2023 03:18:12 +0200 Subject: [PATCH] Fix handling files with spaces in their path Signed-off-by: falkTX --- mod/host.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mod/host.py b/mod/host.py index 23a46898..f01fd64f 100644 --- a/mod/host.py +++ b/mod/host.py @@ -21,6 +21,7 @@ from random import randint from tornado import gen, iostream from tornado.ioloop import IOLoop, PeriodicCallback +from urllib.parse import quote, unquote import os, json, socket, time, logging, sys import shutil @@ -233,7 +234,7 @@ def get_all_good_and_bad_pedalboards(ptype): 'broken': False, 'factory': False, 'hasTrialPlugins': False, - 'uri': "file://" + DEFAULT_PEDALBOARD, + 'uri': "file://" + quote(DEFAULT_PEDALBOARD), 'bundle': DEFAULT_PEDALBOARD, 'title': UNTITLED_PEDALBOARD_NAME, 'version': 0, @@ -2139,7 +2140,7 @@ def report_current_state(self, websocket): # load plugin state if relevant if crashed and self.pedalboard_path: - self.send_notmodified("state_load {}".format(self.pedalboard_path)) + self.send_notmodified("state_load \"{}\"".format(self.pedalboard_path)) # now load plugin parameters and addressings for instance_id, pluginData in self.plugins.items(): @@ -2901,7 +2902,7 @@ def preset_save_new(self, instance, name, callback): break def add_bundle_callback(ok): - preseturi = "file://%s.ttl" % os.path.join(presetbundle, symbolname) + preseturi = "file://%s.ttl" % quote(os.path.join(presetbundle, symbolname)) pluginData['preset'] = preseturi os_sync() callback({ @@ -2920,7 +2921,7 @@ def host_callback(ok): rescan_plugin_presets(plugin_uri) self.add_bundle(presetbundle, add_bundle_callback) - self.send_notmodified("preset_save %d \"%s\" %s %s.ttl" % (instance_id, + self.send_notmodified("preset_save %d \"%s\" \"%s\" %s.ttl" % (instance_id, name.replace('"','\\"'), presetbundle, symbolname), host_callback, datatype='boolean') @@ -2939,7 +2940,7 @@ def preset_save_replace(self, instance, olduri, presetbundle, name, callback): symbolname = symbolify(name)[:32] def add_bundle_callback(ok): - preseturi = "file://%s.ttl" % os.path.join(presetbundle, symbolname) + preseturi = "file://%s.ttl" % quote(os.path.join(presetbundle, symbolname)) pluginData['preset'] = preseturi os_sync() callback({ @@ -2961,7 +2962,7 @@ def host_callback(ok): def start(_): # remove old preset ttl files, without removing the whole dir if olduri.startswith("file:///"): - oldpath = olduri[7:] + oldpath = unquote(olduri[7:]) if os.path.exists(oldpath): os.remove(oldpath) oldpath = os.path.join(os.path.dirname(oldpath), "manifest.ttl") @@ -2970,7 +2971,7 @@ def start(_): rescan_plugin_presets(plugin_uri) pluginData['preset'] = "" - self.send_notmodified("preset_save %d \"%s\" %s %s.ttl" % (instance_id, + self.send_notmodified("preset_save %d \"%s\" \"%s\" %s.ttl" % (instance_id, name.replace('"','\\"'), presetbundle, symbolname), host_callback, datatype='boolean') @@ -3648,7 +3649,7 @@ def load(self, bundlepath, isDefault=False, abort_catcher=None): if bundlepath: self.load_pb_snapshots(bundlepath) - self.send_notmodified("state_load {}".format(bundlepath)) + self.send_notmodified("state_load \"{}\"".format(bundlepath)) self.addressings.load(bundlepath, instances, skippedPortAddressings, abort_catcher) if abort_catcher is not None and abort_catcher.get('abort', False): @@ -3990,7 +3991,7 @@ def state_saved_cb(ok): callback(True, bundlepath, newTitle) # ask host to save any needed extra state - self.send_notmodified("state_save {}".format(bundlepath), state_saved_cb, datatype='boolean') + self.send_notmodified("state_save \"{}\"".format(bundlepath), state_saved_cb, datatype='boolean') return bundlepath, newTitle @@ -5414,7 +5415,7 @@ def rcallback(ok, bundlepath, newTitle): 'broken': False, 'factory': False, 'hasTrialPlugins': False, - 'uri': "file://" + bundlepath, + 'uri': "file://" + quote(bundlepath), 'bundle': bundlepath, 'title': title, 'version': 0, @@ -6171,7 +6172,7 @@ def host_callback(ok): self.save_state_snapshots(self.pedalboard_path) self.save_state_mainfile(self.pedalboard_path, self.pedalboard_name, titlesym) - self.send_notmodified("state_save {}".format(self.pedalboard_path), host_callback) + self.send_notmodified("state_save \"{}\"".format(self.pedalboard_path), host_callback) def hmi_reset_current_pedalboard(self, callback): logging.debug("hmi reset current pedalboard")