Skip to content

Commit

Permalink
Merge pull request #2260 from headlamp-k8s/replace-plugin-rename
Browse files Browse the repository at this point in the history
app: Do not use rename to move plugin folders
  • Loading branch information
joaquimrocha authored Sep 3, 2024
2 parents 30df8e7 + a7dbbca commit 01fe61b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions app/electron/plugin-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ interface PluginData {
artifacthubVersion: string;
}

/**
* Move directories from currentPath to newPath by copying.
* @param currentPath from this path
* @param newPath to this path
*/
function moveDirs(currentPath: string, newPath: string) {
try {
fs.cpSync(currentPath, newPath, { recursive: true, force: true });
fs.rmSync(currentPath, { recursive: true });
console.log(`Moved directory from ${currentPath} to ${newPath}`);
} catch (err) {
console.error(`Error moving directory from ${currentPath} to ${newPath}:`, err);
throw err;
}
}

export class PluginManager {
/**
* Installs a plugin from the specified URL.
Expand Down Expand Up @@ -84,7 +100,7 @@ export class PluginManager {
fs.mkdirSync(destinationFolder, { recursive: true });
}
// move the plugin to the destination folder
fs.renameSync(tempFolder, path.join(destinationFolder, path.basename(name)));
moveDirs(tempFolder, path.join(destinationFolder, path.basename(name)));
if (progressCallback) {
progressCallback({ type: 'success', message: 'Plugin Installed' });
}
Expand Down Expand Up @@ -162,7 +178,7 @@ export class PluginManager {
fs.mkdirSync(pluginDir, { recursive: true });

// move the plugin to the destination folder
fs.renameSync(tempFolder, pluginDir);
moveDirs(tempFolder, pluginDir);
if (progressCallback) {
progressCallback({ type: 'success', message: 'Plugin Updated' });
}
Expand Down
20 changes: 18 additions & 2 deletions plugins/headlamp-plugin/plugin-management/plugin-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ const envPaths = require('env-paths');
// // });
// }

/**
* Move directories from currentPath to newPath by copying.
* @param currentPath from this path
* @param newPath to this path
*/
function moveDirs(currentPath, newPath) {
try {
fs.cpSync(currentPath, newPath, { recursive: true, force: true });
fs.rmSync(currentPath, { recursive: true });
console.log(`Moved directory from ${currentPath} to ${newPath}`);
} catch (err) {
console.error(`Error moving directory from ${currentPath} to ${newPath}:`, err);
throw err;
}
}

class PluginManager {
/**
* Installs a plugin from the specified URL.
Expand Down Expand Up @@ -57,7 +73,7 @@ class PluginManager {
fs.mkdirSync(destinationFolder, { recursive: true });
}
// move the plugin to the destination folder
fs.renameSync(tempFolder, path.join(destinationFolder, path.basename(name)));
moveDirs(tempFolder, path.join(destinationFolder, path.basename(name)));
if (progressCallback) {
progressCallback({ type: 'success', message: 'Plugin Installed' });
}
Expand Down Expand Up @@ -129,7 +145,7 @@ class PluginManager {
fs.mkdirSync(pluginDir, { recursive: true });

// move the plugin to the destination folder
fs.renameSync(tempFolder, pluginDir);
moveDirs(tempFolder, pluginDir);
if (progressCallback) {
progressCallback({ type: 'success', message: 'Plugin Updated' });
}
Expand Down

0 comments on commit 01fe61b

Please sign in to comment.