Repository navigation
Avoid panic during update index - #570
Merged
Merged
Conversation
added 2 commits
August 7, 2015 15:00
When using make with append, both a capacity and length must be used in the make call. If only the length is used the array will have len zero values at the beginning and append will start adding values at the end. This is a small number of values so just skip make altogether.
Contributor
Author
|
Marking this for review as is, it is only fixing the index lock problem. Using the update-index output to drive progress ended up being messier than I'd like so I'm going to punt on that for now. There are a couple of optimizations for speeding up the checkout, I'll put those in a new PR so this can ship. |
Contributor
|
👍 Although this will conflict with #573 😭 |
sinbad
added a commit
to sinbad/git-lfs
that referenced
this pull request
Aug 14, 2015
Contributor
|
I've pre-emptively merged this into #573 to head off any merge conflicts. |
rubyist
added a commit
that referenced
this pull request
Aug 14, 2015
Avoid panic during update index
Contributor
Author
|
Thanks for the review, one of these times I'll submit a PR that doesn't conflict with yours! |
chrisd8088
added a commit
that referenced
this pull request
Oct 16, 2025
In PR #527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. At present, we do not have any tests of these commands' behaviour when they unable to create a subdirectory because a regular file already exists with the same name. In these cases, we expect the commands to report an error but otherwise continue and ultimately return a zero exit code. This has been true since commit e909264 of PR #570, when we revised the "git lfs checkout" command so it would not panic if the DecodePointerFromFile() function in our "lfs" package returned an error other than an ErrNotExist error. In particular, the stat(2) system call, which is invoked by the DecodePointerFromFile() function via the Stat() function of the "os" package in the standard Go library, will return an ENOTDIR error number on Unix systems when any of the components of a given path prefix are not directories. Before we adjust how the "git lfs checkout" and "git lfs pull" commands check and create files, we add a pair of new tests which validate that the commands make no changes when a file exists in place of a directory which would otherwise be created by the commands. After each time these tests run a "git lfs checkout" or "git lfs pull" command, they also check that none of the pre-existing alterations to the working tree have been accidentally staged in the Git index. In the normal case, when these commands successfully update a Git LFS file in the working tree, they should then call the "git update-index" command to refresh the modification timestamp Git has cached for the file. However, when a directory in the path between the root of the working tree and a Git LFS file has been replaced with a file, our commands should not update the Git index. In order for our tests to confirm this is the case they call a new assert_clean_index() test helper function which runs a "git diff-index --cached HEAD" command to check that no unexpected changes have been staged in the index. When our new tests run on Unix systems, we expect the "stat" system call to appear in the error messages output by the "git lfs checkout" and "git lfs pull" commands, along with a file path relative to the current working directory and a generic "Checkout error" message. This log message is reported by the Run() method of the singleCheckout structure in our "commands" package when the DecodePointerFromFile() function returns an error that the "os" package's IsNotExist() function considers not equivalent to an ErrNotExist error. (Note that in subsequent commits we will adjust the text of the log message and change the reported file path to be relative to the root of the repository.) On Windows, our new tests expect a different error message, however, because under the same test conditions the Stat() function of the "os" package does return an error that the IsNotExist() function considers equivalent to an ErrNotExist error. As a result, the Run() method of our singleCheckout structure handles the errors differently, and proceeds to call the RunToPath() method of the same structure, which invokes the SmudgeToFile() method of the GitFilter structure in our "lfs" package. That method performs another Stat() call to check the size and permissions mode of any extant file at the given path, but ignores any errors which might be returned. Next, the SmudgeToFile() method runs the Create() function from the "os" package to try to create or truncate a file at the provided path. When an ancestor in the path is not a directory but a file this function returns an error, which the SmudgeToFile() method then returns wrapped with a "could not create working directory file" message. Finally, the Run() method of the singleCheckout structure reports this error message along with its own "could not check out" message and a file path relative to the root of the repository. Therefore these are the messages and file paths our new tests check for on Windows. The Stat() and Lstat() functions of the "os" package share a common internal implementation on Windows, and the details of this internal stat() function and the "syscall" package of the Go standard library explain why, given our test conditions, the Stat() function returns an error equivalent to an ErrNotExist error on Windows but not on Unix systems. The internal implementation of the Stat() and Lstat() functions on Windows invokes the CreateFileW() Windows API function with the OPEN_EXISTING flag, and that system call returns an ERROR_FILE_NOT_FOUND error number when no file exists at the given path. The "syscall" package in the Go standard library then maps this error number to an ErrNotExist error, unlike how it handles the ENOTDIR error number on Unix systems: https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L66-L71 https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L80-L85 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_windows.go#L182-L186 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_unix.go#L126-L127 https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#parameters
chrisd8088
added a commit
that referenced
this pull request
Oct 16, 2025
In PR #527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. At present, we do not have any tests of these commands' behaviour when they unable to create a subdirectory because a regular file already exists with the same name. In these cases, we expect the commands to report an error but otherwise continue and ultimately return a zero exit code. This has been true since commit e909264 of PR #570, when we revised the "git lfs checkout" command so it would not panic if the DecodePointerFromFile() function in our "lfs" package returned an error other than an ErrNotExist error. In particular, the stat(2) system call, which is invoked by the DecodePointerFromFile() function via the Stat() function of the "os" package in the standard Go library, will return an ENOTDIR error number on Unix systems when any of the components of a given path prefix are not directories. Before we adjust how the "git lfs checkout" and "git lfs pull" commands check and create files, we add a pair of new tests which validate that the commands make no changes when a file exists in place of a directory which would otherwise be created by the commands. After each time these tests run a "git lfs checkout" or "git lfs pull" command, they also check that none of the pre-existing alterations to the working tree have been accidentally staged in the Git index. In the normal case, when these commands successfully update a Git LFS file in the working tree, they should then call the "git update-index" command to refresh the modification timestamp Git has cached for the file. However, when a directory in the path between the root of the working tree and a Git LFS file has been replaced with a file, our commands should not update the Git index. In order for our tests to confirm this is the case they call a new assert_clean_index() test helper function which runs a "git diff-index --cached HEAD" command to check that no unexpected changes have been staged in the index. When our new tests run on Unix systems, we expect the "stat" system call to appear in the error messages output by the "git lfs checkout" and "git lfs pull" commands, along with a file path relative to the current working directory and a generic "Checkout error" message. This log message is reported by the Run() method of the singleCheckout structure in our "commands" package when the DecodePointerFromFile() function returns an error that the "os" package's IsNotExist() function considers not equivalent to an ErrNotExist error. (Note that in subsequent commits we will adjust the text of the log message and change the reported file path to be relative to the root of the repository.) On Windows, our new tests expect a different error message, however, because under the same test conditions the Stat() function of the "os" package does return an error that the IsNotExist() function considers equivalent to an ErrNotExist error. As a result, the Run() method of our singleCheckout structure handles the errors differently, and proceeds to call the RunToPath() method of the same structure, which invokes the SmudgeToFile() method of the GitFilter structure in our "lfs" package. That method performs another Stat() call to check the size and permissions mode of any extant file at the given path, but ignores any errors which might be returned. Next, the SmudgeToFile() method runs the Create() function from the "os" package to try to create or truncate a file at the provided path. When an ancestor in the path is not a directory but a file this function returns an error, which the SmudgeToFile() method then returns wrapped with a "could not create working directory file" message. Finally, the Run() method of the singleCheckout structure reports this error message along with its own "could not check out" message and a file path relative to the root of the repository. Therefore these are the messages and file paths our new tests check for on Windows. The Stat() and Lstat() functions of the "os" package share a common internal implementation on Windows, and the details of this internal stat() function and the "syscall" package of the Go standard library explain why, given our test conditions, the Stat() function returns an error equivalent to an ErrNotExist error on Windows but not on Unix systems. The internal implementation of the Stat() and Lstat() functions on Windows invokes the CreateFileW() Windows API function with the OPEN_EXISTING flag, and that system call returns an ERROR_FILE_NOT_FOUND error number when no file exists at the given path. The "syscall" package in the Go standard library then maps this error number to an ErrNotExist error, unlike how it handles the ENOTDIR error number on Unix systems: https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L66-L71 https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L80-L85 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_windows.go#L182-L186 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_unix.go#L126-L127 https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#parameters
hswong3i
pushed a commit
to alvistack/git-lfs-git-lfs
that referenced
this pull request
Oct 18, 2025
In PR git-lfs#527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. At present, we do not have any tests of these commands' behaviour when they unable to create a subdirectory because a regular file already exists with the same name. In these cases, we expect the commands to report an error but otherwise continue and ultimately return a zero exit code. This has been true since commit e909264 of PR git-lfs#570, when we revised the "git lfs checkout" command so it would not panic if the DecodePointerFromFile() function in our "lfs" package returned an error other than an ErrNotExist error. In particular, the stat(2) system call, which is invoked by the DecodePointerFromFile() function via the Stat() function of the "os" package in the standard Go library, will return an ENOTDIR error number on Unix systems when any of the components of a given path prefix are not directories. Before we adjust how the "git lfs checkout" and "git lfs pull" commands check and create files, we add a pair of new tests which validate that the commands make no changes when a file exists in place of a directory which would otherwise be created by the commands. After each time these tests run a "git lfs checkout" or "git lfs pull" command, they also check that none of the pre-existing alterations to the working tree have been accidentally staged in the Git index. In the normal case, when these commands successfully update a Git LFS file in the working tree, they should then call the "git update-index" command to refresh the modification timestamp Git has cached for the file. However, when a directory in the path between the root of the working tree and a Git LFS file has been replaced with a file, our commands should not update the Git index. In order for our tests to confirm this is the case they call a new assert_clean_index() test helper function which runs a "git diff-index --cached HEAD" command to check that no unexpected changes have been staged in the index. When our new tests run on Unix systems, we expect the "stat" system call to appear in the error messages output by the "git lfs checkout" and "git lfs pull" commands, along with a file path relative to the current working directory and a generic "Checkout error" message. This log message is reported by the Run() method of the singleCheckout structure in our "commands" package when the DecodePointerFromFile() function returns an error that the "os" package's IsNotExist() function considers not equivalent to an ErrNotExist error. (Note that in subsequent commits we will adjust the text of the log message and change the reported file path to be relative to the root of the repository.) On Windows, our new tests expect a different error message, however, because under the same test conditions the Stat() function of the "os" package does return an error that the IsNotExist() function considers equivalent to an ErrNotExist error. As a result, the Run() method of our singleCheckout structure handles the errors differently, and proceeds to call the RunToPath() method of the same structure, which invokes the SmudgeToFile() method of the GitFilter structure in our "lfs" package. That method performs another Stat() call to check the size and permissions mode of any extant file at the given path, but ignores any errors which might be returned. Next, the SmudgeToFile() method runs the Create() function from the "os" package to try to create or truncate a file at the provided path. When an ancestor in the path is not a directory but a file this function returns an error, which the SmudgeToFile() method then returns wrapped with a "could not create working directory file" message. Finally, the Run() method of the singleCheckout structure reports this error message along with its own "could not check out" message and a file path relative to the root of the repository. Therefore these are the messages and file paths our new tests check for on Windows. The Stat() and Lstat() functions of the "os" package share a common internal implementation on Windows, and the details of this internal stat() function and the "syscall" package of the Go standard library explain why, given our test conditions, the Stat() function returns an error equivalent to an ErrNotExist error on Windows but not on Unix systems. The internal implementation of the Stat() and Lstat() functions on Windows invokes the CreateFileW() Windows API function with the OPEN_EXISTING flag, and that system call returns an ERROR_FILE_NOT_FOUND error number when no file exists at the given path. The "syscall" package in the Go standard library then maps this error number to an ErrNotExist error, unlike how it handles the ENOTDIR error number on Unix systems: https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L66-L71 https://github.com/golang/go/blob/go1.24.4/src/os/stat_windows.go#L80-L85 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_windows.go#L182-L186 https://github.com/golang/go/blob/go1.24.4/src/syscall/syscall_unix.go#L126-L127 https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will avoid any use of
Panic()while thegit update-indexloop is running. If the process exits whileupdate-indexis in the middle of processing a file, the index can be left in an inconsistent, locked state./cc #558