mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 15:04:16 -07:00
Shorten temp directory (#17901)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
/**
|
||||
* Migration utility to move data from old hash-based directories to new slug-based directories.
|
||||
*/
|
||||
export class StorageMigration {
|
||||
/**
|
||||
* Migrates a directory from an old path to a new path if the old one exists and the new one doesn't.
|
||||
* @param oldPath The old directory path (hash-based).
|
||||
* @param newPath The new directory path (slug-based).
|
||||
*/
|
||||
static async migrateDirectory(
|
||||
oldPath: string,
|
||||
newPath: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
// If the new path already exists, we consider migration done or skipped to avoid overwriting.
|
||||
// If the old path doesn't exist, there's nothing to migrate.
|
||||
if (fs.existsSync(newPath) || !fs.existsSync(oldPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure the parent directory of the new path exists
|
||||
const parentDir = path.dirname(newPath);
|
||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||
|
||||
// Copy (safer and handles cross-device moves)
|
||||
await fs.promises.cp(oldPath, newPath, { recursive: true });
|
||||
} catch (e) {
|
||||
debugLogger.debug(
|
||||
`Storage Migration: Failed to move ${oldPath} to ${newPath}:`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user