Skip to content

Commit b5bd259

Browse files
fix: handle Windows paths in cloneItem and getDirectoryName functions (fixes: #3401) (#3646)
* fix: handle Windows paths in cloneItem and getDirectoryName functions * chore: removed commented lines --------- Co-authored-by: Anoop M D <[email protected]>
1 parent 0633d45 commit b5bd259

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
transformRequestToSaveToFilesystem
2222
} from 'utils/collections';
2323
import { uuid, waitForNextTick } from 'utils/common';
24-
import { PATH_SEPARATOR, getDirectoryName } from 'utils/common/platform';
24+
import { PATH_SEPARATOR, getDirectoryName, isWindowsPath } from 'utils/common/platform';
2525
import { cancelNetworkRequest, sendNetworkRequest } from 'utils/network';
2626

2727
import {
@@ -494,7 +494,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
494494
);
495495
if (!reqWithSameNameExists) {
496496
const dirname = getDirectoryName(item.pathname);
497-
const fullName = path.join(dirname, filename);
497+
const fullName = isWindowsPath(item.pathname) ? path.win32.join(dirname, filename) : path.join(dirname, filename);
498498
const { ipcRenderer } = window;
499499
const requestItems = filter(parentItem.items, (i) => i.type !== 'folder');
500500
itemToSave.seq = requestItems ? requestItems.length + 1 : 1;

packages/bruno-app/src/utils/common/platform.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,25 @@ export const getSubdirectoriesFromRoot = (rootPath, pathname) => {
2424
return relativePath ? relativePath.split(path.sep) : [];
2525
};
2626

27-
export const getDirectoryName = (pathname) => {
28-
// convert to unix style path
29-
pathname = slash(pathname);
3027

31-
return path.dirname(pathname);
28+
export const isWindowsPath = (pathname) => {
29+
30+
if (!isWindowsOS()) {
31+
return false;
32+
}
33+
34+
// Check for Windows drive letter format (e.g., "C:\")
35+
const hasDriveLetter = /^[a-zA-Z]:\\/.test(pathname);
36+
37+
// Check for UNC path format (e.g., "\\server\share") a.k.a. network path || WSL path
38+
const isUNCPath = pathname.startsWith('\\\\');
39+
40+
return hasDriveLetter || isUNCPath;
41+
};
42+
43+
44+
export const getDirectoryName = (pathname) => {
45+
return isWindowsPath(pathname) ? path.win32.dirname(pathname) : path.dirname(pathname);
3246
};
3347

3448
export const isWindowsOS = () => {

0 commit comments

Comments
 (0)