Fix symlink test util
That was resolving the path completely before checking whether the symlink is broken or not.
This commit is contained in:
1 parent
8ef13ba529
commit
f5b99a6e34
3 files changed
+18
-11
No files matched your search
@@ -268,9 +268,12 @@ def _test_path(data):
|
||||
import os
|
||||
from octoprint.util.paths import normalize
|
||||
|
||||
path = normalize(data["path"])
|
||||
path = normalize(data["path"], real=False)
|
||||
if not path:
|
||||
return jsonify(path=path, exists=False, typeok=False, access=False, result=False)
|
||||
return jsonify(path=path, exists=False, typeok=False, broken_symlink=False, access=False, result=False)
|
||||
|
||||
unreal_path = path
|
||||
path = os.path.realpath(path)
|
||||
|
||||
check_type = None
|
||||
check_access = []
|
||||
@@ -293,17 +296,17 @@ def _test_path(data):
|
||||
# check if path exists
|
||||
exists = os.path.exists(path)
|
||||
if not exists:
|
||||
if os.path.islink(path):
|
||||
if os.path.islink(unreal_path):
|
||||
# broken symlink, see #2644
|
||||
logging.getLogger(__name__).error("{} is a broken symlink")
|
||||
return jsonify(path=path, exists=False, typeok=False, access=False, result=False)
|
||||
logging.getLogger(__name__).error("{} is a broken symlink pointing at non existing {}".format(unreal_path, path))
|
||||
return jsonify(path=unreal_path, exists=False, typeok=False, broken_symlink=True, access=False, result=False)
|
||||
|
||||
elif check_type == "dir" and allow_create_dir:
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except:
|
||||
logging.getLogger(__name__).exception("Error while trying to create {}".format(path))
|
||||
return jsonify(path=path, exists=False, typeok=False, access=False, result=False)
|
||||
return jsonify(path=path, exists=False, typeok=False, broken_symlink=False, access=False, result=False)
|
||||
else:
|
||||
exists = True
|
||||
|
||||
@@ -332,9 +335,9 @@ def _test_path(data):
|
||||
os.remove(test_path)
|
||||
except:
|
||||
logging.getLogger(__name__).exception("Error while testing if {} is really writable".format(path))
|
||||
return jsonify(path=path, exists=exists, typeok=typeok, access=False, result=False)
|
||||
return jsonify(path=path, exists=exists, typeok=typeok, broken_symlink=False, access=False, result=False)
|
||||
|
||||
return jsonify(path=path, exists=exists, typeok=typeok, access=access, result=exists and typeok and access)
|
||||
return jsonify(path=path, exists=exists, typeok=typeok, broken_symlink=False, access=access, result=exists and typeok and access)
|
||||
|
||||
|
||||
def _test_url(data):
|
||||
|
||||
@@ -473,7 +473,9 @@ $(function() {
|
||||
OctoPrint.util.testPath(path, opts)
|
||||
.done(function(response) {
|
||||
if (!response.result) {
|
||||
if (!response.exists) {
|
||||
if (response.broken_symlink) {
|
||||
self.testFolderConfigText[folder](gettext("The path is a broken symlink."));
|
||||
} else if (!response.exists) {
|
||||
self.testFolderConfigText[folder](gettext("The path does not exist and cannot be created."));
|
||||
} else if (!response.typeok) {
|
||||
self.testFolderConfigText[folder](gettext("The path is not a folder."));
|
||||
|
||||
@@ -5,7 +5,7 @@ __author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
def normalize(path, expand_user=True, expand_vars=True, **kwargs):
|
||||
def normalize(path, expand_user=True, expand_vars=True, real=True, **kwargs):
|
||||
import os
|
||||
|
||||
if path is None:
|
||||
@@ -15,5 +15,7 @@ def normalize(path, expand_user=True, expand_vars=True, **kwargs):
|
||||
path = os.path.expanduser(path)
|
||||
if expand_vars:
|
||||
path = os.path.expandvars(path)
|
||||
path = os.path.realpath(os.path.abspath(path))
|
||||
path = os.path.abspath(path)
|
||||
if real:
|
||||
path = os.path.realpath(path)
|
||||
return path
|
||||
Reference in new issue
Block a user