MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / removeMarkedSection

Function removeMarkedSection

src/installer/targets/shared.ts:205–233  ·  view source on GitHub ↗
(
  filePath: string,
  startMarker: string,
  endMarker: string,
)

Source from the content-addressed store, hash-verified

203 * the markers weren't present, `kept` when the file didn't exist.
204 */
205export function removeMarkedSection(
206 filePath: string,
207 startMarker: string,
208 endMarker: string,
209): 'removed' | 'not-found' | 'kept' {
210 if (!fs.existsSync(filePath)) return 'kept';
211
212 let content: string;
213 try {
214 content = fs.readFileSync(filePath, 'utf-8');
215 } catch {
216 return 'kept';
217 }
218
219 const startIdx = content.indexOf(startMarker);
220 const endIdx = content.indexOf(endMarker);
221 if (startIdx === -1 || endIdx <= startIdx) return 'not-found';
222
223 const before = content.substring(0, startIdx).trimEnd();
224 const after = content.substring(endIdx + endMarker.length).trimStart();
225 const joined = before + (before && after ? '\n\n' : '') + after;
226
227 if (joined.trim() === '') {
228 try { fs.unlinkSync(filePath); } catch { /* ignore */ }
229 } else {
230 atomicWriteFileSync(filePath, joined.trim() + '\n');
231 }
232 return 'removed';
233}

Callers 5

removeInstructionsEntryFunction · 0.90
removeInstructionsEntryFunction · 0.90
removeInstructionsEntryFunction · 0.90
removeInstructionsEntryFunction · 0.90

Calls 1

atomicWriteFileSyncFunction · 0.85

Tested by

no test coverage detected