mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-29 07:21:27 -07:00
Shorten temp directory (#17901)
This commit is contained in:
@@ -38,6 +38,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
disableMouseEvents: vi.fn(),
|
||||
enterAlternateScreen: vi.fn(),
|
||||
disableLineWrapping: vi.fn(),
|
||||
ProjectRegistry: vi.fn().mockImplementation(() => ({
|
||||
initialize: vi.fn(),
|
||||
getShortId: vi.fn().mockReturnValue('project-slug'),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
'shell_history',
|
||||
);
|
||||
}
|
||||
initialize(): Promise<undefined> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
}
|
||||
return {
|
||||
...actual,
|
||||
|
||||
@@ -24,6 +24,7 @@ async function getHistoryFilePath(
|
||||
configStorage?: Storage,
|
||||
): Promise<string> {
|
||||
const storage = configStorage ?? new Storage(projectRoot);
|
||||
await storage.initialize();
|
||||
return storage.getHistoryFilePath();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
},
|
||||
Storage: class {
|
||||
getProjectTempDir = vi.fn(() => '/tmp/global');
|
||||
initialize = vi.fn(() => Promise.resolve(undefined));
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -256,8 +256,11 @@ const saveFileWithXclip = async (tempFilePath: string) => {
|
||||
* @param targetDir The root directory of the current project.
|
||||
* @returns The absolute path to the images directory.
|
||||
*/
|
||||
function getProjectClipboardImagesDir(targetDir: string): string {
|
||||
async function getProjectClipboardImagesDir(
|
||||
targetDir: string,
|
||||
): Promise<string> {
|
||||
const storage = new Storage(targetDir);
|
||||
await storage.initialize();
|
||||
const baseDir = storage.getProjectTempDir();
|
||||
return path.join(baseDir, 'images');
|
||||
}
|
||||
@@ -271,7 +274,7 @@ export async function saveClipboardImage(
|
||||
targetDir: string,
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
const tempDir = getProjectClipboardImagesDir(targetDir);
|
||||
const tempDir = await getProjectClipboardImagesDir(targetDir);
|
||||
await fs.mkdir(tempDir, { recursive: true });
|
||||
|
||||
// Generate a unique filename with timestamp
|
||||
@@ -396,7 +399,7 @@ export async function cleanupOldClipboardImages(
|
||||
targetDir: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const tempDir = getProjectClipboardImagesDir(targetDir);
|
||||
const tempDir = await getProjectClipboardImagesDir(targetDir);
|
||||
const files = await fs.readdir(tempDir);
|
||||
const oneHourAgo = Date.now() - 60 * 60 * 1000;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
spawnAsync: vi.fn(),
|
||||
Storage: class {
|
||||
getProjectTempDir = vi.fn(() => "C:\\User's Files");
|
||||
initialize = vi.fn(() => Promise.resolve(undefined));
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as path from 'node:path';
|
||||
vi.mock('@google/gemini-cli-core', () => ({
|
||||
Storage: vi.fn().mockImplementation(() => ({
|
||||
getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'),
|
||||
initialize: vi.fn().mockResolvedValue(undefined),
|
||||
})),
|
||||
shutdownTelemetry: vi.fn(),
|
||||
isTelemetrySdkInitialized: vi.fn().mockReturnValue(false),
|
||||
|
||||
@@ -102,6 +102,7 @@ async function drainStdin() {
|
||||
|
||||
export async function cleanupCheckpoints() {
|
||||
const storage = new Storage(process.cwd());
|
||||
await storage.initialize();
|
||||
const tempDir = storage.getProjectTempDir();
|
||||
const checkpointsDir = join(tempDir, 'checkpoints');
|
||||
try {
|
||||
|
||||
@@ -362,8 +362,12 @@ export async function cleanupToolOutputFiles(
|
||||
}
|
||||
|
||||
const retentionConfig = settings.general.sessionRetention;
|
||||
const tempDir =
|
||||
projectTempDir ?? new Storage(process.cwd()).getProjectTempDir();
|
||||
let tempDir = projectTempDir;
|
||||
if (!tempDir) {
|
||||
const storage = new Storage(process.cwd());
|
||||
await storage.initialize();
|
||||
tempDir = storage.getProjectTempDir();
|
||||
}
|
||||
const toolOutputDir = path.join(tempDir, TOOL_OUTPUTS_DIR);
|
||||
|
||||
// Check if directory exists
|
||||
|
||||
Reference in New Issue
Block a user