Skip to content

Commit 5c41dcf

Browse files
mikolalysenkoclaude
andcommitted
Auto-run GC after remove command
- Remove command now automatically cleans up unused blobs after updating manifest - Aligns with existing behavior in download command - Ensures orphaned blobs are cleaned up immediately 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 99a492e commit 5c41dcf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/commands/remove.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import type { CommandModule } from 'yargs'
44
import {
55
PatchManifestSchema,
66
DEFAULT_PATCH_MANIFEST_PATH,
7+
type PatchManifest,
78
} from '../schema/manifest-schema.js'
9+
import {
10+
cleanupUnusedBlobs,
11+
formatCleanupResult,
12+
} from '../utils/cleanup-blobs.js'
813

914
interface RemoveArgs {
1015
identifier: string
@@ -15,7 +20,7 @@ interface RemoveArgs {
1520
async function removePatch(
1621
identifier: string,
1722
manifestPath: string,
18-
): Promise<{ removed: string[]; notFound: boolean }> {
23+
): Promise<{ removed: string[]; notFound: boolean; manifest: PatchManifest }> {
1924
// Read and parse manifest
2025
const manifestContent = await fs.readFile(manifestPath, 'utf-8')
2126
const manifestData = JSON.parse(manifestContent)
@@ -52,7 +57,7 @@ async function removePatch(
5257
)
5358
}
5459

55-
return { removed, notFound: !foundMatch }
60+
return { removed, notFound: !foundMatch, manifest }
5661
}
5762

5863
export const removeCommand: CommandModule<{}, RemoveArgs> = {
@@ -91,7 +96,7 @@ export const removeCommand: CommandModule<{}, RemoveArgs> = {
9196
process.exit(1)
9297
}
9398

94-
const { removed, notFound } = await removePatch(
99+
const { removed, notFound, manifest } = await removePatch(
95100
argv.identifier,
96101
manifestPath,
97102
)
@@ -107,7 +112,14 @@ export const removeCommand: CommandModule<{}, RemoveArgs> = {
107112
}
108113

109114
console.log(`\nManifest updated at ${manifestPath}`)
110-
console.log('Tip: Run "socket-patch gc" to clean up unused blob files.')
115+
116+
// Clean up unused blobs after removing patches
117+
const socketDir = path.dirname(manifestPath)
118+
const blobsPath = path.join(socketDir, 'blobs')
119+
const cleanupResult = await cleanupUnusedBlobs(manifest, blobsPath, false)
120+
if (cleanupResult.blobsRemoved > 0) {
121+
console.log(`\n${formatCleanupResult(cleanupResult, false)}`)
122+
}
111123

112124
process.exit(0)
113125
} catch (err) {

0 commit comments

Comments
 (0)