Skip to content

refactor: remove temp file logic from copyFile for simplicity#19

Merged
laggu merged 3 commits intodevelopfrom
gv-019
Feb 17, 2026
Merged

refactor: remove temp file logic from copyFile for simplicity#19
laggu merged 3 commits intodevelopfrom
gv-019

Conversation

@laggu
Copy link
Copy Markdown
Owner

@laggu laggu commented Feb 16, 2026

Summary

  • temp 파일 + rename 방식의 atomic write를 직접 쓰기 방식으로 변경
  • 소스 파일이 항상 존재하므로, 대상 파일 손상 시 재sync로 복구 가능
  • 코드 복잡도 감소 (~60줄 → ~20줄)

Changes

  • internal/gitvolume/fs.go: copyFile() 함수 단순화

Trade-off

상황 결과 복구 방법
복사 중 크래시 대상 파일 손상 가능 sync 재실행

결정 근거: 소스가 항상 원본으로 존재하므로 복잡한 보호 로직 불필요

Testing

  • go test ./... 통과
  • go build 성공

Closes #19

- Replace atomic write (temp file + rename) with direct file write
- Source files always exist, so damaged targets can be recovered via re-sync
- Reduces code complexity from ~60 lines to ~20 lines

Closes #19
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @laggu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 Pull Request는 internal/gitvolume/fs.go 파일 내 copyFile 함수의 로직을 리팩토링하여 단순화합니다. 기존의 임시 파일 생성 및 원자적 이름 변경 방식을 제거하고, 파일을 목적지로 직접 복사하는 방식으로 변경되었습니다. 이는 소스 파일이 항상 원본으로 존재하여 대상 파일 손상 시 재동기화를 통해 복구가 가능하다는 전제 하에 코드 복잡도를 줄이고 가독성을 높이는 것을 목표로 합니다.

Highlights

  • copyFile 함수 로직 변경: copyFile 함수가 임시 파일과 이름 변경을 통한 원자적 쓰기 방식에서 직접 쓰기 방식으로 변경되었습니다.
  • 복구 메커니즘: 대상 파일 손상 시 원본 소스 파일이 항상 존재하므로 재동기화를 통해 복구할 수 있도록 변경되었습니다.
  • 코드 복잡도 감소: copyFile 함수의 코드 복잡도가 약 60줄에서 20줄로 크게 감소했습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/gitvolume/fs.go
    • copyFile 함수에서 임시 파일 생성, 내용 복사, 권한 설정, 원자적 이름 변경을 포함하는 복잡한 로직이 제거되었습니다.
    • copyFile 함수가 소스 파일을 열고 대상 파일을 생성한 후 직접 내용을 복사하고 동기화하는 간결한 방식으로 변경되었습니다.
    • copyFile 함수의 주석이 변경된 동작 방식(직접 복사, 실패 시 재동기화로 복구 가능)을 반영하도록 업데이트되었습니다.
Activity
  • 이 Pull Request에 대한 인간 활동(댓글, 검토 등)은 아직 없습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR simplifies the copyFile function by removing complex atomic write logic. However, this change introduces a high-severity security vulnerability, making the application susceptible to symlink following attacks and breaking file permission synchronization for existing files. It is strongly recommended to address these security concerns, potentially by reverting to the atomic write implementation or implementing explicit checks. Additionally, consider improving error handling in defer statements and wrapping errors according to the style guide for better code stability and clarity.

Comment thread internal/gitvolume/fs.go
Comment thread internal/gitvolume/fs.go Outdated
- Merge copyDirNoSymlink, copyDirNoSymlinkWithForce, copyDirNoSymlinkRecursive into single function
- Update call sites in add.go and sync.go
- Return Close() error instead of ignoring it in defer
- Add code review guidelines to .gemini/styleguide.md
@laggu
Copy link
Copy Markdown
Owner Author

laggu commented Feb 16, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR simplifies the logic of the copyFile function, reducing code complexity by moving from a temporary file and rename approach to direct writing. While this change is a positive refactoring, it introduces a critical security regression. The new copyFile implementation no longer prevents overwriting symbolic link targets, meaning it could follow symbolic links at the destination and potentially allow arbitrary file overwrites if a symbolic link is present. This issue is exacerbated by syncCopy (line 109) using os.Stat instead of os.Lstat, which incorrectly identifies symlinks. Additionally, the error handling within the new copyFile function violates the repository's style guide. Addressing these security and style concerns is crucial for robustness and security.

Comment thread internal/gitvolume/fs.go
Comment thread internal/gitvolume/sync.go
Comment thread internal/gitvolume/fs.go
Comment thread internal/gitvolume/fs.go
@laggu laggu merged commit 56056d7 into develop Feb 17, 2026
@laggu laggu deleted the gv-019 branch February 23, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant