mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-01 07:24:38 -07:00
bug(core): Fix minor bug in migration logic. (#18661)
This commit is contained in:
@@ -64,6 +64,25 @@ describe('StorageMigration', () => {
|
|||||||
expect(fs.existsSync(path.join(newPath, 'old.txt'))).toBe(false);
|
expect(fs.existsSync(path.join(newPath, 'old.txt'))).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('migrates even if new path contains .project_root (ProjectRegistry initialization)', async () => {
|
||||||
|
const oldPath = path.join(tempDir, 'old-hash');
|
||||||
|
const newPath = path.join(tempDir, 'new-slug');
|
||||||
|
fs.mkdirSync(oldPath);
|
||||||
|
fs.mkdirSync(newPath);
|
||||||
|
fs.writeFileSync(path.join(oldPath, 'history.db'), 'data');
|
||||||
|
fs.writeFileSync(path.join(newPath, '.project_root'), 'path');
|
||||||
|
|
||||||
|
await StorageMigration.migrateDirectory(oldPath, newPath);
|
||||||
|
|
||||||
|
expect(fs.existsSync(path.join(newPath, 'history.db'))).toBe(true);
|
||||||
|
expect(fs.readFileSync(path.join(newPath, 'history.db'), 'utf8')).toBe(
|
||||||
|
'data',
|
||||||
|
);
|
||||||
|
expect(fs.readFileSync(path.join(newPath, '.project_root'), 'utf8')).toBe(
|
||||||
|
'path',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('creates parent directory for new path if it does not exist', async () => {
|
it('creates parent directory for new path if it does not exist', async () => {
|
||||||
const oldPath = path.join(tempDir, 'old-hash');
|
const oldPath = path.join(tempDir, 'old-hash');
|
||||||
const newPath = path.join(tempDir, 'sub', 'new-slug');
|
const newPath = path.join(tempDir, 'sub', 'new-slug');
|
||||||
|
|||||||
@@ -22,12 +22,21 @@ export class StorageMigration {
|
|||||||
newPath: string,
|
newPath: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// If the new path already exists, we consider migration done or skipped to avoid overwriting.
|
if (!fs.existsSync(oldPath)) {
|
||||||
// If the old path doesn't exist, there's nothing to migrate.
|
|
||||||
if (fs.existsSync(newPath) || !fs.existsSync(oldPath)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(newPath)) {
|
||||||
|
const files = await fs.promises.readdir(newPath);
|
||||||
|
// If it contains more than just the .project_root file, it's not a fresh directory from ProjectRegistry
|
||||||
|
if (
|
||||||
|
files.length > 1 ||
|
||||||
|
(files.length === 1 && files[0] !== '.project_root')
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the parent directory of the new path exists
|
// Ensure the parent directory of the new path exists
|
||||||
const parentDir = path.dirname(newPath);
|
const parentDir = path.dirname(newPath);
|
||||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user