Skip to content

Commit

Permalink
Merge pull request #7019 from markotoplak/fix-windows-different-drives
Browse files Browse the repository at this point in the history
[FIX] Save Data: fix when saving to different drives on Windows
  • Loading branch information
thocevar authored Feb 7, 2025
2 parents 8542122 + f995a0b commit 357b3af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Orange/widgets/utils/save/owsavebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ def last_dir(self, absolute_path):
self.stored_path = absolute_path
workflow_dir = self.workflowEnv().get("basedir", None)
if workflow_dir:
relative_path = os.path.relpath(absolute_path, start=workflow_dir)
if not relative_path.startswith(".."):
self.stored_path = relative_path
try:
relative_path = os.path.relpath(absolute_path, start=workflow_dir)
except ValueError: # on Windows for paths on different drives
pass
else:
if not relative_path.startswith(".."):
self.stored_path = relative_path

def _abs_path_from_setting(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion Orange/widgets/utils/save/tests/test_owsavebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ class OWSave(OWSaveBase):
# absolute stored paths
for workflow_dir, filename in [("C:/Temp", "C:/Folder/abc.csv"),
("C:/Temp/Project", "C:/Temp/abc.csv"),
("C:\\Temp\\Project", "C:\\Temp\\abc.csv")]:
("C:\\Temp\\Project", "C:\\Temp\\abc.csv"),
("C:/Temp", "D:/Folder/abc.csv"),
("C:\\Temp\\Project", "D:\\Temp\\abc.csv")]:
widget.workflowEnv = lambda bd=workflow_dir: {"basedir": bd}
widget.filename = filename
self.assertTrue(os.path.isabs(widget.stored_path))
Expand Down

0 comments on commit 357b3af

Please sign in to comment.