Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Conversation

@vdye
Copy link
Collaborator

@vdye vdye commented Feb 16, 2023

Closes #13.

The first two commits remove Wishlist.md (replaced with issues linked in the commit description) and doc.go (I think it's just unused?). The third commit fixes #13 by creating leading parent directories returning an empty result if the file doesn't exist, and the fourth improves error reporting when trying to read the file.

Manual testing confirmed that the missing file doesn't trigger an error (and that it's still successfully created by CreateRepository()). I was also able to trigger an intentional failure of ReadFileLines() (by creating ~/git-bundle-server with sudo mkdir -m 700 ~/git-bundle-server) and confirmed that the permission denied error was reported:

$ git-bundle-server init [email protected]:rust-lang/rust.git rust-lang/rust
2023/02/16 13:55:02 Failed with error: failed to parse routes file: open /Users/vdye/git-bundle-server//routes: permission denied

@vdye vdye self-assigned this Feb 16, 2023
Copy link
Collaborator

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

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

Approving, but have some questions about the side effect in ReadFileLines(). It's worth thinking about alternatives, but it's not a blocker to moving forward.

file, err := os.Open(filename)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So much simpler!

Comment on lines +68 to +75
pathErr, ok := err.(*os.PathError)
if ok && pathErr.Err == syscall.ENOENT {
// If the file doesn't exist, return empty result rather than an
// error
return []string{}, nil
} else {
return nil, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good.

nit: the commit message no longer matches the change.

Copy link
Collaborator

@ldennington ldennington left a comment

Choose a reason for hiding this comment

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

Lovely!

vdye added 4 commits February 17, 2023 08:26
Remove the 'Wishlist.md' file. The first two items in the list (custom root
directory for repository storage and tracing) have been added to the
repository issue tracker ([1] & [2], respectively). The last (HTTPS web
server support) was added in 5377d04 (web-server: capture and use web server
options, 2023-01-26) and its immediately preceding commits [3].

[1] #25
[2] #22
[3] #10

Signed-off-by: Victoria Dye <[email protected]>
The 'doc.go' file seems to be leftover from an earlier version of the bundle
server prototype. It currently contains no code and is not required for a
successful build, so remove it.

Signed-off-by: Victoria Dye <[email protected]>
If the file argument to 'ReadFileLines()' does not exist on disk, return an
empty string list (corresponding to an empty file) with no error rather than
pass the error on to the caller.

This removes a pre-existing side-effect behavior of 'ReadFileLines()', where
the 'os.O_CREATE' flag would create the file if it was missing when read. It
would not create leading directories, though, leading to unhandled error
cases (e.g. in 'git-bundle-server init' without '~/git-bundle-server'). By
instead returning an empty result for any missing file, these errors are
avoided.

Signed-off-by: Victoria Dye <[email protected]>
Print the error received by 'CreateRepository()'/'RemoveRoute()' when
attempting to read the repository routes file. This will help users identify
the cause of the failure (e.g., permissions issue) so it can be remedied.

Signed-off-by: Victoria Dye <[email protected]>
@vdye vdye merged commit 725df38 into main Feb 17, 2023
@vdye vdye deleted the vdye/init-bugfix branch February 17, 2023 16:36
@vdye vdye added this to the v1.0 milestone Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-bundle-server init fails when route file parent directory doesn't exist

4 participants