diff --git a/packages/bruno-app/src/providers/App/useCollectionTreeSync.js b/packages/bruno-app/src/providers/App/useCollectionTreeSync.js index ae394a9eb..b7663adb0 100644 --- a/packages/bruno-app/src/providers/App/useCollectionTreeSync.js +++ b/packages/bruno-app/src/providers/App/useCollectionTreeSync.js @@ -33,6 +33,10 @@ const useCollectionTreeSync = () => { }; const _collectionTreeUpdated = (type, val) => { + if(window.__IS_DEV__) { + console.log(type); + console.log(val); + } if (type === 'addDir') { dispatch( collectionAddDirectoryEvent({ 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 71785884e..4b3e37229 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -22,6 +22,7 @@ import { } from 'utils/collections'; import { collectionSchema, itemSchema, environmentSchema, environmentsSchema } from '@usebruno/schema'; import { waitForNextTick } from 'utils/common'; +import { getDirectoryName } from 'utils/common/platform'; import { sendNetworkRequest, cancelNetworkRequest } from 'utils/network'; import { @@ -232,14 +233,14 @@ export const renameItem = (newName, itemUid, collectionUid) => (dispatch, getSta return reject(new Error('Unable to locate item')); } - const dirname = path.dirname(item.pathname); + const dirname = getDirectoryName(item.pathname); let newPathname = ''; if (item.type === 'folder') { - newPathname = `${dirname}${PATH_SEPARATOR}${trim(newName)}`; + newPathname = path.join(dirname, trim(newName)); } else { const filename = resolveRequestFilename(newName); - newPathname = `${dirname}${PATH_SEPARATOR}${filename}`; + newPathname = path.join(dirname, filename); } const { ipcRenderer } = window; @@ -291,8 +292,8 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat } else { const reqWithSameNameExists = find(parentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); if (!reqWithSameNameExists) { - const dirname = path.dirname(item.pathname); - const fullName = `${dirname}${PATH_SEPARATOR}${filename}`; + const dirname = getDirectoryName(item.pathname); + const fullName = 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/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index fc132bb1e..621d355d7 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -23,7 +23,7 @@ import { areItemsTheSameExceptSeqUpdate } from 'utils/collections'; import { parseQueryParams, stringifyQueryParams } from 'utils/url'; -import { getSubdirectoriesFromRoot } from 'utils/common/platform'; +import { getSubdirectoriesFromRoot, getDirectoryName } from 'utils/common/platform'; const PATH_SEPARATOR = path.sep; @@ -712,7 +712,7 @@ export const collectionsSlice = createSlice({ const collection = findCollectionByUid(state.collections, file.meta.collectionUid); if (collection) { - const dirname = path.dirname(file.meta.pathname); + const dirname = getDirectoryName(file.meta.pathname); const subDirectories = getSubdirectoriesFromRoot(collection.pathname, dirname); let currentPath = collection.pathname; let currentSubItems = collection.items; diff --git a/packages/bruno-app/src/utils/common/platform.js b/packages/bruno-app/src/utils/common/platform.js index be5af1110..036cafe0a 100644 --- a/packages/bruno-app/src/utils/common/platform.js +++ b/packages/bruno-app/src/utils/common/platform.js @@ -1,5 +1,6 @@ import trim from 'lodash/trim'; import path from 'path'; +import slash from './slash'; export const isElectron = () => { if (!window) { @@ -18,9 +19,17 @@ export const resolveRequestFilename = (name) => { }; export const getSubdirectoriesFromRoot = (rootPath, pathname) => { - if (!path.isAbsolute(pathname)) { - throw new Error('Invalid path!'); - } + // convert to unix style path + pathname = slash(pathname); + rootPath = slash(rootPath); + const relativePath = path.relative(rootPath, pathname); return relativePath ? relativePath.split(path.sep) : []; }; + +export const getDirectoryName = (pathname) => { + // convert to unix style path + pathname = slash(pathname); + + return path.dirname(pathname); +} diff --git a/packages/bruno-app/src/utils/common/slash.js b/packages/bruno-app/src/utils/common/slash.js new file mode 100644 index 000000000..d12807566 --- /dev/null +++ b/packages/bruno-app/src/utils/common/slash.js @@ -0,0 +1,20 @@ +/** + * MIT License + * + * Copyright (c) Sindre Sorhus (https://sindresorhus.com) + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +const slash = (path) => { + const isExtendedLengthPath = /^\\\\\?\\/.test(path); + + if (isExtendedLengthPath) { + return path; + } + + return path.replace(/\\/g, '/'); +} + +export default slash;