diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py index e41530f..2438e6d 100644 --- a/web/pgadmin/tools/backup/__init__.py +++ b/web/pgadmin/tools/backup/__init__.py @@ -243,7 +243,17 @@ def filename_with_file_manager_path(_file, create_file=True): with open(_file, 'a'): pass - return fs_short_path(_file) + short_path = fs_short_path(_file) + + # fs_short_path() function may return empty path on Windows + # if directory doesn't exists. In that case we strip the last path + # component and get the short path. + if os.name == 'nt' and short_path == '': + base_name = os.path.basename(_file) + dir_name = os.path.dirname(_file) + short_path = fs_short_path(dir_name) + '\\' + base_name + + return short_path @blueprint.route( diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py index 54a599c..75bef23 100644 --- a/web/pgadmin/utils/__init__.py +++ b/web/pgadmin/utils/__init__.py @@ -223,6 +223,8 @@ if IS_WIN: buf_size = len(_path) while True: res = ctypes.create_unicode_buffer(buf_size) + # Note:- _GetShortPathNameW may return empty value + # if directory doesn't exists. needed = _GetShortPathNameW(_path, res, buf_size) if buf_size >= needed: