Nir Soffer has uploaded a new change for review.
Change subject: fileUtils: Normalize initial double slashes
......................................................................
fileUtils: Normalize initial double slashes
POSIX allows both /path and //path. The second slash may be interpreted
in an implementation-defined manner. The Linux interpretation seems to
be to ignore the double slash, so it seems to be safe to remove it.
See
https://bugs.python.org/issue26329 for more info.
Change-Id: Ifa3f8724e9a423263b5676d691308d0188b26935
Bug-Url: XXX
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/storage/fileUtils.py
M tests/fileUtilTests.py
2 files changed, 20 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/61578/1
diff --git a/lib/vdsm/storage/fileUtils.py b/lib/vdsm/storage/fileUtils.py
index fcd8829..49ee937 100644
--- a/lib/vdsm/storage/fileUtils.py
+++ b/lib/vdsm/storage/fileUtils.py
@@ -36,8 +36,6 @@
import types
import warnings
-from os.path import normpath
-
import six
from vdsm import constants
@@ -106,6 +104,22 @@
return address.hosttail_join(host, tail)
+def normpath(path):
+ """
+ Normalize file system path.
+
+ POSIX allows both /path and //path. The second slash may be interpreted in
+ an implementation-defined manner. The Linux interpretation seems to be to
+ ignore the double slash, so it seems to be safe to remove it.
+
+ See
https://bugs.python.org/issue26329 for more info.
+ """
+ path = os.path.normpath(path)
+ if path.startswith('//'):
+ path = path[1:]
+ return path
+
+
def is_port(port_str):
if port_str.startswith('0'):
return False
diff --git a/tests/fileUtilTests.py b/tests/fileUtilTests.py
index a9a7270..ec4c278 100644
--- a/tests/fileUtilTests.py
+++ b/tests/fileUtilTests.py
@@ -180,10 +180,14 @@
@permutations([
# Remote paths without a port
("server:/path", "server:/path"),
+ ("server://path", "server:/path"),
+ ("server:///path", "server:/path"),
("server:/path/", "server:/path"),
("server:/pa:th", "server:/pa:th"),
("server:/path//", "server:/path"),
("server:/", "server:/"),
+ ("server://", "server:/"),
+ ("server:///", "server:/"),
("12.34.56.78:/", "12.34.56.78:/"),
("[2001:db8::60fe:5bf:febc:912]:/",
"[2001:db8::60fe:5bf:febc:912]:/"),
("server:01234:/", "server:01234:"),
--
To view, visit
https://gerrit.ovirt.org/61578
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa3f8724e9a423263b5676d691308d0188b26935
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>