import (
"bufio"
"bytes"
+ "context"
"io"
"math"
"strconv"
func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
batchStdinReader, batchStdinWriter := io.Pipe()
batchStdoutReader, batchStdoutWriter := io.Pipe()
+ ctx, ctxCancel := context.WithCancel(DefaultContext)
+ closed := make(chan struct{})
cancel := func() {
_ = batchStdinReader.Close()
_ = batchStdinWriter.Close()
_ = batchStdoutReader.Close()
_ = batchStdoutWriter.Close()
+ ctxCancel()
+ <-closed
}
go func() {
stderr := strings.Builder{}
- err := NewCommand("cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
+ err := NewCommandContext(ctx, "cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
if err != nil {
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdoutWriter.Close()
_ = batchStdinReader.Close()
}
+ close(closed)
}()
// For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
// so let's create a batch stdin and stdout
batchStdinReader, batchStdinWriter := io.Pipe()
batchStdoutReader, batchStdoutWriter := nio.Pipe(buffer.New(32 * 1024))
+ ctx, ctxCancel := context.WithCancel(DefaultContext)
+ closed := make(chan struct{})
cancel := func() {
_ = batchStdinReader.Close()
_ = batchStdinWriter.Close()
_ = batchStdoutReader.Close()
_ = batchStdoutWriter.Close()
+ ctxCancel()
+ <-closed
}
go func() {
stderr := strings.Builder{}
- err := NewCommand("cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
+ err := NewCommandContext(ctx, "cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
if err != nil {
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdoutWriter.Close()
_ = batchStdinReader.Close()
}
+ close(closed)
}()
// For simplicities sake we'll us a buffered reader to read from the cat-file --batch
import (
"os"
+ "runtime"
"syscall"
"time"
)
+const windowsSharingViolationError syscall.Errno = 32
+
// Remove removes the named file or (empty) directory with at most 5 attempts.
func Remove(name string) error {
var err error
continue
}
+ if unwrapped == windowsSharingViolationError && runtime.GOOS == "windows" {
+ // try again
+ <-time.After(100 * time.Millisecond)
+ continue
+ }
+
if unwrapped == syscall.ENOENT {
// it's already gone
return nil
continue
}
+ if unwrapped == windowsSharingViolationError && runtime.GOOS == "windows" {
+ // try again
+ <-time.After(100 * time.Millisecond)
+ continue
+ }
+
if unwrapped == syscall.ENOENT {
// it's already gone
return nil
continue
}
+ if unwrapped == windowsSharingViolationError && runtime.GOOS == "windows" {
+ // try again
+ <-time.After(100 * time.Millisecond)
+ continue
+ }
+
if i == 0 && os.IsNotExist(err) {
return err
}