Skip to content

fmt does not preserve file permissions #1635

@hohobilly

Description

@hohobilly

Describe the bug
When running swag fmt, the formatter updates the permission of the files.
This minor difference usually don't cause any issues, only in some cases like if someone is running swag fmt with root permission. The owner is changed the root. With group read permission gone, the user cannot access the formatted file.
Overall, I believe fmt should preserve the permission from the original file as a default behavior.

To Reproduce

  1. Check the file permission before formatting
> ls -l
-rw-r--r--  1 user user  7755 Aug 2 9:42 main.go
  1. run swag fmt
  2. Check the file permission again
> ls -l
-rw------- 1 user user  7755 Aug 2 9:43 main.go 
// If running with root, because user is change, user don't have permission to read the file anymore

Expected behavior
fmt should preserve the permission from the original file.

Your swag version
v1.8.12

Your go version
e.g. 1.12.0

Desktop (please complete the following information):

  • OS: macOS
  • Version: Ventura 13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions