mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 15:33:11 +01:00
Fix/rename-collection-support-wsl (#2892)
* fix: normalize wsl path for rename item * added isWSLPath, normalizeWslPath * revert normalize action on actions.js * added WSL path checking and apply Win UNC normalize
This commit is contained in:
parent
8b76ecede3
commit
0b9554c8cc
@ -374,6 +374,7 @@ export const newFolder = (folderName, collectionUid, itemUid) => (dispatch, getS
|
||||
});
|
||||
};
|
||||
|
||||
// rename item
|
||||
export const renameItem = (newName, itemUid, collectionUid) => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
||||
@ -718,7 +719,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
|
||||
const pathParams = parsePathParams(requestUrl);
|
||||
each(pathParams, (pathParm) => {
|
||||
pathParams.enabled = true;
|
||||
pathParm.type = 'path'
|
||||
pathParm.type = 'path';
|
||||
});
|
||||
|
||||
const params = [...queryParams, ...pathParams];
|
||||
|
@ -13,7 +13,9 @@ const {
|
||||
browseFiles,
|
||||
createDirectory,
|
||||
searchForBruFiles,
|
||||
sanitizeDirectoryName
|
||||
sanitizeDirectoryName,
|
||||
isWSLPath,
|
||||
normalizeWslPath,
|
||||
} = require('../utils/filesystem');
|
||||
const { openCollectionDialog } = require('../app/collections');
|
||||
const { generateUidBasedOnHash, stringifyJson, safeParseJSON, safeStringifyJSON } = require('../utils/common');
|
||||
@ -326,6 +328,14 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
// rename item
|
||||
ipcMain.handle('renderer:rename-item', async (event, oldPath, newPath, newName) => {
|
||||
try {
|
||||
// Normalize paths if they are WSL paths
|
||||
if (isWSLPath(oldPath)) {
|
||||
oldPath = normalizeWslPath(oldPath);
|
||||
}
|
||||
if (isWSLPath(newPath)) {
|
||||
newPath = normalizeWslPath(newPath);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(oldPath)) {
|
||||
throw new Error(`path: ${oldPath} does not exist`);
|
||||
}
|
||||
|
@ -50,6 +50,18 @@ const normalizeAndResolvePath = (pathname) => {
|
||||
return path.resolve(pathname);
|
||||
};
|
||||
|
||||
function isWSLPath(pathname) {
|
||||
// Check if the path starts with the WSL prefix
|
||||
// eg. "\\wsl.localhost\Ubuntu\home\user\bruno\collection\scripting\api\req\getHeaders.bru"
|
||||
return pathname.startsWith('/wsl.localhost/') || pathname.startsWith('\\wsl.localhost\\');
|
||||
}
|
||||
|
||||
function normalizeWslPath(pathname) {
|
||||
// Replace the WSL path prefix and convert forward slashes to backslashes
|
||||
// This is done to achieve WSL paths (linux style) to Windows UNC equivalent (Universal Naming Conversion)
|
||||
return pathname.replace(/^\/wsl.localhost/, '\\\\wsl.localhost').replace(/\//g, '\\');
|
||||
}
|
||||
|
||||
const writeFile = async (pathname, content) => {
|
||||
try {
|
||||
fs.writeFileSync(pathname, content, {
|
||||
@ -143,6 +155,8 @@ const searchForBruFiles = (dir) => {
|
||||
return searchForFiles(dir, '.bru');
|
||||
};
|
||||
|
||||
// const isW
|
||||
|
||||
const sanitizeDirectoryName = (name) => {
|
||||
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
||||
};
|
||||
@ -154,6 +168,8 @@ module.exports = {
|
||||
isFile,
|
||||
isDirectory,
|
||||
normalizeAndResolvePath,
|
||||
isWSLPath,
|
||||
normalizeWslPath,
|
||||
writeFile,
|
||||
writeBinaryFile,
|
||||
hasJsonExtension,
|
||||
|
Loading…
Reference in New Issue
Block a user