Skip to content

Commit e87d608

Browse files
Fix sync on Windows
1 parent 9f3bf65 commit e87d608

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

cloudinary_cli/modules/sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from cloudinary_cli.utils.api_utils import query_cld_folder, upload_file, download_file
1010
from cloudinary_cli.utils.file_utils import walk_dir, delete_empty_dirs, get_destination_folder, \
11-
normalize_file_extension
11+
normalize_file_extension, posix_rel_path
1212
from cloudinary_cli.utils.json_utils import print_json, read_json_from_file, write_json_to_file
1313
from cloudinary_cli.utils.utils import logger, run_tasks_concurrently, get_user_action, invert_dict
1414

@@ -171,8 +171,8 @@ def _print_sync_status(self, success, errors):
171171
def _save_sync_meta_file(self, upload_results):
172172
diverse_filenames = {}
173173
for local_path, remote_path in upload_results.items():
174-
local = normalize_file_extension(path.relpath(local_path, self.local_dir))
175-
remote = normalize_file_extension(path.relpath(remote_path, self.remote_dir))
174+
local = normalize_file_extension(posix_rel_path(local_path, self.local_dir))
175+
remote = normalize_file_extension(posix_rel_path(remote_path, self.remote_dir))
176176
if local != remote:
177177
diverse_filenames[local] = remote
178178

cloudinary_cli/utils/api_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from cloudinary.utils import cloudinary_url
99

1010
from cloudinary_cli.defaults import logger
11-
from cloudinary_cli.utils.file_utils import normalize_file_extension
11+
from cloudinary_cli.utils.file_utils import normalize_file_extension, posix_rel_path
1212
from cloudinary_cli.utils.json_utils import print_json, write_json_to_file
1313
from cloudinary_cli.utils.utils import print_help, log_exception, confirm_action, \
1414
get_command_params, merge_responses, normalize_list_params
@@ -31,7 +31,7 @@ def query_cld_folder(folder):
3131
res = expression.execute()
3232

3333
for asset in res['resources']:
34-
rel_path = path.relpath(asset_source(asset), folder)
34+
rel_path = posix_rel_path(asset_source(asset), folder)
3535
files[normalize_file_extension(rel_path)] = {
3636
"type": asset['type'],
3737
"resource_type": asset['resource_type'],

cloudinary_cli/utils/file_utils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import stat
33
from os import walk, path, listdir, rmdir, sep
44
from os.path import split, relpath, abspath
5+
from pathlib import PurePath
56

67
from cloudinary_cli.defaults import logger
78
from cloudinary_cli.utils.utils import etag
@@ -45,7 +46,7 @@ def walk_dir(root_dir, include_hidden=False):
4546
files = [f for f in files if not is_hidden(root, f)]
4647
dirs[:] = [d for d in dirs if not is_hidden(root, d)]
4748

48-
relative_path = relpath(root, root_dir) if root_dir != root else ""
49+
relative_path = posix_rel_path(root, root_dir) if root_dir != root else ""
4950
for file in files:
5051
full_path = path.join(root, file)
5152
relative_file_path = "/".join(p for p in [relative_path, file] if p)
@@ -107,7 +108,7 @@ def get_destination_folder(cloudinary_folder: str, file_path: str, parent: str =
107108
folder_path = []
108109

109110
parent_path = abspath(parent) if parent else None
110-
splitted = split(relpath(file_path, parent_path))
111+
splitted = split(posix_rel_path(file_path, parent_path))
111112

112113
if splitted[0]:
113114
folder_path = splitted[0].split(sep)
@@ -127,3 +128,14 @@ def normalize_file_extension(filename: str) -> str:
127128
extension_alias = FORMAT_ALIASES.get(extension, extension)
128129

129130
return ".".join([p for p in [filename, extension_alias] if p])
131+
132+
133+
def posix_rel_path(end, start) -> str:
134+
"""
135+
Returns a relative path in posix style on any system.
136+
137+
:param end: The end path.
138+
:param start: The start path.
139+
:return: The Relative path.
140+
"""
141+
return PurePath(relpath(end, start)).as_posix()

0 commit comments

Comments
 (0)