Skip to content

Commit 847e838

Browse files
authored
Merge pull request #12 from BeyteFlow/copilot/sub-pr-8
fix: preserve file permissions in ConflictResolver atomic write
2 parents a22ffaa + d177c5f commit 847e838

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

git-ai/src/services/ConflictResolver.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ export class ConflictResolver {
173173
// Atomic write: write to a temp file, fsync, then rename into place.
174174
const tempPath = path.join(targetParent, `.tmp-${process.pid}-${randomBytes(8).toString('hex')}`);
175175
const buffer = Buffer.from(resolvedContent, 'utf-8');
176-
const tempHandle = await fs.open(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW, 0o644);
176+
let fileMode = 0o644;
177+
try {
178+
const stat = await fs.lstat(targetPath);
179+
fileMode = stat.mode & 0o777;
180+
} catch {
181+
// Target does not exist; use default mode 0o644
182+
}
183+
const tempHandle = await fs.open(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW, fileMode);
177184
try {
178185
await tempHandle.writeFile(buffer);
179186
await tempHandle.sync();

0 commit comments

Comments
 (0)