From 8ddaaf378a6ec13496e9b7a79762a29588835f91 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Fri, 13 Dec 2024 08:24:37 +0530 Subject: [PATCH] fix: handle Windows paths in cloneItem and getDirectoryName functions --- .../ReduxStore/slices/collections/actions.js | 4 ++-- .../bruno-app/src/utils/common/platform.js | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 75c6f2cb..7973e57a 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -21,7 +21,7 @@ import { transformRequestToSaveToFilesystem } from 'utils/collections'; import { uuid, waitForNextTick } from 'utils/common'; -import { PATH_SEPARATOR, getDirectoryName } from 'utils/common/platform'; +import { PATH_SEPARATOR, getDirectoryName, isWindowsPath } from 'utils/common/platform'; import { cancelNetworkRequest, sendNetworkRequest } from 'utils/network'; import { @@ -494,7 +494,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat ); if (!reqWithSameNameExists) { const dirname = getDirectoryName(item.pathname); - const fullName = path.join(dirname, filename); + const fullName = isWindowsPath(item.pathname) ? path.win32.join(dirname, filename) : path.join(dirname, filename); const { ipcRenderer } = window; const requestItems = filter(parentItem.items, (i) => i.type !== 'folder'); itemToSave.seq = requestItems ? requestItems.length + 1 : 1; diff --git a/packages/bruno-app/src/utils/common/platform.js b/packages/bruno-app/src/utils/common/platform.js index ddfdb3a1..adf5f9ab 100644 --- a/packages/bruno-app/src/utils/common/platform.js +++ b/packages/bruno-app/src/utils/common/platform.js @@ -24,11 +24,28 @@ export const getSubdirectoriesFromRoot = (rootPath, pathname) => { return relativePath ? relativePath.split(path.sep) : []; }; + +export const isWindowsPath = (pathname) => { + + if (!isWindowsOS()) { + return false; + } + + // Check for Windows drive letter format (e.g., "C:\") + const hasDriveLetter = /^[a-zA-Z]:\\/.test(pathname); + + // Check for UNC path format (e.g., "\\server\share") a.k.a. network path || WSL path + const isUNCPath = pathname.startsWith('\\\\'); + + return hasDriveLetter || isUNCPath; +}; + + export const getDirectoryName = (pathname) => { // convert to unix style path - pathname = slash(pathname); + // pathname = slash(pathname); - return path.dirname(pathname); + return isWindowsPath(pathname) ? path.win32.dirname(pathname) : path.dirname(pathname); }; export const isWindowsOS = () => {