nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bytedance/sonic
Pull request #250 (2022-06-28 05:48:40)

fix:(ast) checkRaw() check if node is nil pointer first
reslove #248 


Patch:
diff --git a/ast/node.go b/ast/node.go
index f08a9c4..a11718e 100644
--- a/ast/node.go
+++ b/ast/node.go
@@ -156,12 +156,12 @@ func (self *Node) Raw() (string, error) {
 }
 
 func (self *Node) checkRaw() error {
-    if self.IsRaw() {
-        self.parseRaw(false)
-    }
     if err := self.Check(); err != nil {
         return err
     }
+    if self.IsRaw() {
+        self.parseRaw(false)
+    }
     return nil
 }
 


Test patch:
diff --git a/issue_test/issue248_test.go b/issue_test/issue248_test.go
new file mode 100644
index 0000000..6f16564
--- /dev/null
+++ b/issue_test/issue248_test.go
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2021 ByteDance Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package issue_test
+
+import (
+    `testing`
+
+    `github.com/bytedance/sonic`
+    `github.com/stretchr/testify/require`
+)
+
+func TestIssue248(t *testing.T) {
+    var d = `{}`
+    n, err := sonic.GetFromString(d)
+    require.Nil(t, err)
+    v := n.GetByPath("a", 0)
+    require.Nil(t, v)
+    s, err := v.Get("a").Index(0).String()
+    require.NotNil(t, err)
+    require.Equal(t, "", s)
+}
\ No newline at end of file
Repository: bytedance/sonic
Pull request #296 (2022-09-08 07:56:05)

fix:(decoder) more loose repeatable condition for `StreamDecoder`

AsterDY: fix #293 

Patch:
diff --git a/decoder/stream.go b/decoder/stream.go
index 32c11cd..06dc818 100644
--- a/decoder/stream.go
+++ b/decoder/stream.go
@@ -127,7 +127,7 @@ read_more:
 
 func (self StreamDecoder) repeatable(err error) bool {
     if ee, ok := err.(SyntaxError); ok && 
-    (ee.Code == types.ERR_EOF || (ee.Code == types.ERR_INVALID_CHAR && self.i == len(self.s)-1)) {
+    (ee.Code == types.ERR_EOF || (ee.Code == types.ERR_INVALID_CHAR && self.i >= len(self.s)-1)) {
         return true
     }
     return false


Test patch:
diff --git a/issue_test/issue293_test.go b/issue_test/issue293_test.go
index eb1ca76..28660cf 100644
--- a/issue_test/issue293_test.go
+++ b/issue_test/issue293_test.go
@@ -35,4 +35,20 @@ func TestIssue293(t *testing.T) {
     if err != nil {
         t.Fatal(err)
     }
+}
+
+func TestIssue293Sign(t *testing.T) {
+    left := `{"a":`
+    var data = left+strings.Repeat(" ", 4096 - len(left)-1) + "-33.0}"
+    sd := decoder.NewStreamDecoder(strings.NewReader(data))
+    var v = struct{
+        A json.RawMessage
+    }{}
+    err := sd.Decode(&v)
+    if err != nil {
+	if e, ok := err.(decoder.SyntaxError); ok {
+	    t.Fatal(e.Description())
+	}
+        t.Fatal(err)
+    }
 }
\ No newline at end of file
Repository: bytedance/sonic
Pull request #685 (2024-08-06 07:06:42)

feat:(ast) nill Node can marshal to `null`


Patch:
diff --git a/ast/decode.go b/ast/decode.go
index 2593d4f..6690d51 100644
--- a/ast/decode.go
+++ b/ast/decode.go
@@ -29,8 +29,10 @@ import (
 // Hack: this is used for both checking space and cause firendly compile errors in 32-bit arch.
 const _Sonic_Not_Support_32Bit_Arch__Checking_32Bit_Arch_Here = (1 << ' ') | (1 << '\t') | (1 << '\r') | (1 << '\n')
 
+var bytesNull   = []byte("null")
+
 const (
-    bytesNull   = "null"
+    strNull   = "null"
     bytesTrue   = "true"
     bytesFalse  = "false"
     bytesObject = "{}"
@@ -64,7 +66,7 @@ func decodeNull(src string, pos int) (ret int) {
     if ret > len(src) {
         return -int(types.ERR_EOF)
     }
-    if src[pos:ret] == bytesNull {
+    if src[pos:ret] == strNull {
         return ret
     } else {
         return -int(types.ERR_INVALID_CHAR)
diff --git a/ast/encode.go b/ast/encode.go
index 345f91f..eae0bd2 100644
--- a/ast/encode.go
+++ b/ast/encode.go
@@ -91,6 +91,10 @@ func quoteString(e *[]byte, s string) {
 var bytesPool   = sync.Pool{}
 
 func (self *Node) MarshalJSON() ([]byte, error) {
+	if self == nil {
+		return bytesNull, nil
+	}
+
     buf := newBuffer()
     err := self.encode(buf)
     if err != nil {
@@ -159,7 +163,7 @@ func (self *Node) encodeRaw(buf *[]byte) error {
 }
 
 func (self *Node) encodeNull(buf *[]byte) error {
-    *buf = append(*buf, bytesNull...)
+    *buf = append(*buf, strNull...)
     return nil
 }
 


Test patch:
diff --git a/ast/encode_test.go b/ast/encode_test.go
index 45446eb..67cdb90 100644
--- a/ast/encode_test.go
+++ b/ast/encode_test.go
@@ -120,7 +120,23 @@ func TestEncodeValue(t *testing.T) {
     }
 }
 
+func BenchmarkNil(b *testing.B) {
+	for i:=0; i<b.N; i++ {
+		null := (*Node)(nil)
+		_, _ = null.MarshalJSON()
+	}
+}
+
 func TestEncodeNode(t *testing.T) {
+	null := (*Node)(nil)
+	js, err := null.MarshalJSON()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if string(js) != "null" {
+		t.Fatal(string(js))
+	}
+
     data := `{"a":[{},[],-0.1,true,false,null,""],"b":0,"c":true,"d":false,"e":null,"g":""}`
     root, e := NewSearcher(data).GetByPath()
     if e != nil {
Repository: google/ko
Pull request #68 (2019-08-12 00:04:00)

Add permissions to the kodata directory.
I suspect that this may be a source of problems reading kodata with nonroot,
but it is probably worth doing either way.

dprotaso: > Additionally, windows can only set 0222, 0444, or 0666, none of which are executable.

For my curiosity do you have a reference/link?

mattmoor: @dprotaso this is copy/pasta from (IIRC) @evankanderson's comments elsewhere in this file.

Patch:
diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go
index 7d9d5e22..f6b11fbb 100644
--- a/pkg/build/gobuild.go
+++ b/pkg/build/gobuild.go
@@ -299,6 +299,10 @@ func (g *gobuild) tarKoData(importpath string) (*bytes.Buffer, error) {
 			return tw.WriteHeader(&tar.Header{
 				Name:     kodataRoot,
 				Typeflag: tar.TypeDir,
+				// Use a fixed Mode, so that this isn't sensitive to the directory and umask
+				// under which it was created. Additionally, windows can only set 0222,
+				// 0444, or 0666, none of which are executable.
+				Mode: 0555,
 			})
 		}
 		if err != nil {


Test patch:
diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go
index 00ca7e66..a80d9279 100644
--- a/pkg/build/gobuild_test.go
+++ b/pkg/build/gobuild_test.go
@@ -255,7 +255,7 @@ func TestGoBuild(t *testing.T) {
 	t.Run("check app layer contents", func(t *testing.T) {
 		expectedHash := v1.Hash{
 			Algorithm: "sha256",
-			Hex:       "63b6e090921b79b61e7f5fba44d2ea0f81215d9abac3d005dda7cb9a1f8a025d",
+			Hex:       "4379f30a6c6f66221c3c54dddd378fcfa5a7304a6655ff783b102069c0f943ab",
 		}
 		appLayer := ls[baseLayers]
Repository: google/ko
Pull request #77 (2019-08-16 20:56:21)

Use GOOS/GOARCH from base image
Small progress towards #6 


Patch:
diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go
index c140cf10..2a26f2af 100644
--- a/pkg/build/gobuild.go
+++ b/pkg/build/gobuild.go
@@ -41,7 +41,7 @@ const (
 
 // GetBase takes an importpath and returns a base v1.Image.
 type GetBase func(string) (v1.Image, error)
-type builder func(string, bool) (string, error)
+type builder func(string, v1.Platform, bool) (string, error)
 
 type gobuild struct {
 	getBase              GetBase
@@ -147,7 +147,7 @@ func (g *gobuild) importPackage(s string) (*gb.Package, error) {
 	return nil, moduleErr
 }
 
-func build(ip string, disableOptimizations bool) (string, error) {
+func build(ip string, platform v1.Platform, disableOptimizations bool) (string, error) {
 	tmpDir, err := ioutil.TempDir("", "ko")
 	if err != nil {
 		return "", err
@@ -165,8 +165,12 @@ func build(ip string, disableOptimizations bool) (string, error) {
 	cmd := exec.Command("go", args...)
 
 	// Last one wins
-	// TODO(mattmoor): GOARCH=amd64
-	cmd.Env = append([]string{"CGO_ENABLED=0", "GOOS=linux"}, os.Environ()...)
+	defaultEnv := []string{
+		"CGO_ENABLED=0",
+		"GOOS=" + platform.OS,
+		"GOARCH=" + platform.Architecture,
+	}
+	cmd.Env = append(defaultEnv, os.Environ()...)
 
 	var output bytes.Buffer
 	cmd.Stderr = &output
@@ -362,8 +366,22 @@ func (g *gobuild) tarKoData(importpath string) (*bytes.Buffer, error) {
 
 // Build implements build.Interface
 func (gb *gobuild) Build(s string) (v1.Image, error) {
+	// Determine the appropriate base image for this import path.
+	base, err := gb.getBase(s)
+	if err != nil {
+		return nil, err
+	}
+	cf, err := base.ConfigFile()
+	if err != nil {
+		return nil, err
+	}
+	platform := v1.Platform{
+		OS:           cf.OS,
+		Architecture: cf.Architecture,
+	}
+
 	// Do the build into a temporary file.
-	file, err := gb.build(s, gb.disableOptimizations)
+	file, err := gb.build(s, platform, gb.disableOptimizations)
 	if err != nil {
 		return nil, err
 	}
@@ -414,12 +432,6 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
 		},
 	})
 
-	// Determine the appropriate base image for this import path.
-	base, err := gb.getBase(s)
-	if err != nil {
-		return nil, err
-	}
-
 	// Augment the base image with our application layer.
 	withApp, err := mutate.Append(base, layers...)
 	if err != nil {


Test patch:
diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go
index 7f6aef1a..f6270974 100644
--- a/pkg/build/gobuild_test.go
+++ b/pkg/build/gobuild_test.go
@@ -102,7 +102,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
 }
 
 // A helper method we use to substitute for the default "build" method.
-func writeTempFile(s string, _ bool) (string, error) {
+func writeTempFile(s string, _ v1.Platform, _ bool) (string, error) {
 	tmpDir, err := ioutil.TempDir("", "ko")
 	if err != nil {
 		return "", err
Repository: google/ko
Pull request #107 (2019-11-07 07:35:55)

Ignore null YAML documents when using a label selector.
Resolving a YAML that ends in an empty YAML node.
```shell
go run ./cmd/ko resolve -l foo=bar -f - <<END
apiVersion: v1
kind: A
metadata:
  labels:
    foo: bar
---
END
```
Before this change:
```
error processing import paths in "-": error evaluating selector: yaml doesn't represent a k8s object
exit status 1
```

After this change:
```
apiVersion: v1
kind: A
metadata:
  labels:
    foo: bar

---

```


Patch:
diff --git a/pkg/resolve/selector.go b/pkg/resolve/selector.go
index 722e1318..1c4fc352 100644
--- a/pkg/resolve/selector.go
+++ b/pkg/resolve/selector.go
@@ -47,6 +47,11 @@ func MatchesSelector(doc *yaml.Node, selector labels.Selector) (bool, error) {
 }
 
 func docKind(doc *yaml.Node) (string, error) {
+	// Null nodes will fail the check below, so simply ignore them.
+	if doc.Tag == "!!null" {
+		return "", nil
+	}
+
 	it := FromNode(doc).
 		Filter(Intersect(
 			WithKind(yaml.MappingNode),


Test patch:
diff --git a/pkg/commands/resolver_test.go b/pkg/commands/resolver_test.go
index 06f43e33..ce1465fd 100644
--- a/pkg/commands/resolver_test.go
+++ b/pkg/commands/resolver_test.go
@@ -16,6 +16,7 @@ package commands
 
 import (
 	"bytes"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"testing"
@@ -101,6 +102,36 @@ func TestResolveMultiDocumentYAMLs(t *testing.T) {
 	}
 }
 
+func TestResolveMultiDocumentYAMLsWithSelector(t *testing.T) {
+	passesSelector := `apiVersion: something/v1
+kind: Foo
+metadata:
+  labels:
+    qux: baz
+`
+	failsSelector := `apiVersion: other/v2
+kind: Bar
+`
+	// Note that this ends in '---', so it in ends in a final null YAML document.
+	inputYAML := []byte(fmt.Sprintf("%s---\n%s---", passesSelector, failsSelector))
+	base := mustRepository("gcr.io/multi-pass")
+
+	outputYAML, err := resolveFile(
+		yamlToTmpFile(t, inputYAML),
+		testBuilder,
+		kotesting.NewFixedPublish(base, testHashes),
+		&options.SelectorOptions{
+			Selector: "qux=baz",
+		},
+		&options.StrictOptions{})
+	if err != nil {
+		t.Fatalf("ImageReferences(%v) = %v", string(inputYAML), err)
+	}
+	if diff := cmp.Diff(passesSelector, string(outputYAML)); diff != "" {
+		t.Errorf("resolveFile (-want +got) = %v", diff)
+	}
+}
+
 func mustRepository(s string) name.Repository {
 	n, err := name.NewRepository(s)
 	if err != nil {
diff --git a/pkg/resolve/selector_test.go b/pkg/resolve/selector_test.go
index 406d0de7..3a122922 100644
--- a/pkg/resolve/selector_test.go
+++ b/pkg/resolve/selector_test.go
@@ -139,6 +139,11 @@ func TestMatchesSelector(t *testing.T) {
 		input:    podList,
 		selector: labels.Nothing(),
 		matches:  false,
+	}, {
+		desc: "null node",
+		input: "!!null",
+		selector: labels.Everything(),
+		matches: false,
 	}}
 
 	for _, test := range tests {
Repository: google/ko
Pull request #114 (2019-12-11 19:01:17)

Add entrypoint to PATH
This makes it easier to invoke the binary when using a debug container.
E.g. you could invoke `ko` instead of `/ko-app/ko`.


Patch:
diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go
index 2c7aa10b..f0868107 100644
--- a/pkg/build/gobuild.go
+++ b/pkg/build/gobuild.go
@@ -21,6 +21,7 @@ import (
 	"context"
 	"encoding/json"
 	"errors"
+	"fmt"
 	gb "go/build"
 	"io"
 	"io/ioutil"
@@ -450,6 +451,7 @@ func (gb *gobuild) Build(ctx context.Context, s string) (v1.Image, error) {
 
 	cfg = cfg.DeepCopy()
 	cfg.Config.Entrypoint = []string{appPath}
+	updatePath(cfg, appPath)
 	cfg.Config.Env = append(cfg.Config.Env, "KO_DATA_PATH="+kodataRoot)
 	cfg.Author = "github.com/google/ko"
 
@@ -464,3 +466,24 @@ func (gb *gobuild) Build(ctx context.Context, s string) (v1.Image, error) {
 	}
 	return image, nil
 }
+
+// Append appPath to the PATH environment variable, if it exists. Otherwise,
+// set the PATH environment variable to appPath.
+func updatePath(cf *v1.ConfigFile, appPath string) {
+	for i, env := range cf.Config.Env {
+		parts := strings.SplitN(env, "=", 2)
+		if len(parts) != 2 {
+			// Expect environment variables to be in the form KEY=VALUE, so this is unexpected.
+			continue
+		}
+		key, value := parts[0], parts[1]
+		if key == "PATH" {
+			value = fmt.Sprintf("%s:%s", value, appPath)
+			cf.Config.Env[i] = "PATH=" + value
+			return
+		}
+	}
+
+	// If we get here, we never saw PATH.
+	cf.Config.Env = append(cf.Config.Env, "PATH="+appPath)
+}


Test patch:
diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go
index 9888e705..55fe51b6 100644
--- a/pkg/build/gobuild_test.go
+++ b/pkg/build/gobuild_test.go
@@ -21,6 +21,7 @@ import (
 	"io/ioutil"
 	"path"
 	"path/filepath"
+	"strings"
 	"testing"
 	"time"
 
@@ -336,7 +337,24 @@ func TestGoBuild(t *testing.T) {
 			}
 		}
 		if !found {
-			t.Error("Didn't find expected file in tarball.")
+			t.Error("Didn't find KO_DATA_PATH.")
+		}
+	})
+
+	// Check that PATH contains the produced binary.
+	t.Run("check PATH env var", func(t *testing.T) {
+		cfg, err := img.ConfigFile()
+		if err != nil {
+			t.Errorf("ConfigFile() = %v", err)
+		}
+		found := false
+		for _, entry := range cfg.Config.Env {
+			if strings.HasPrefix(entry, "PATH=") && strings.Contains(entry, "/ko-app/test") {
+				found = true
+			}
+		}
+		if !found {
+			t.Error("Didn't find entrypoint in PATH.")
 		}
 	})
Repository: google/ko
Pull request #127 (2020-01-28 03:57:24)

Fix: Add directory containing binary to PATH
Fixes the PATH environment variable so it contains the directory
containing the binary (i.e., /ko-app) instead of the binary itself
(e.g., /ko-app/ko).

See #114.


Patch:
diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go
index f0868107..38b88fb8 100644
--- a/pkg/build/gobuild.go
+++ b/pkg/build/gobuild.go
@@ -451,7 +451,7 @@ func (gb *gobuild) Build(ctx context.Context, s string) (v1.Image, error) {
 
 	cfg = cfg.DeepCopy()
 	cfg.Config.Entrypoint = []string{appPath}
-	updatePath(cfg, appPath)
+	updatePath(cfg)
 	cfg.Config.Env = append(cfg.Config.Env, "KO_DATA_PATH="+kodataRoot)
 	cfg.Author = "github.com/google/ko"
 
@@ -467,9 +467,9 @@ func (gb *gobuild) Build(ctx context.Context, s string) (v1.Image, error) {
 	return image, nil
 }
 
-// Append appPath to the PATH environment variable, if it exists. Otherwise,
-// set the PATH environment variable to appPath.
-func updatePath(cf *v1.ConfigFile, appPath string) {
+// Append appDir to the PATH environment variable, if it exists. Otherwise,
+// set the PATH environment variable to appDir.
+func updatePath(cf *v1.ConfigFile) {
 	for i, env := range cf.Config.Env {
 		parts := strings.SplitN(env, "=", 2)
 		if len(parts) != 2 {
@@ -478,12 +478,12 @@ func updatePath(cf *v1.ConfigFile, appPath string) {
 		}
 		key, value := parts[0], parts[1]
 		if key == "PATH" {
-			value = fmt.Sprintf("%s:%s", value, appPath)
+			value = fmt.Sprintf("%s:%s", value, appDir)
 			cf.Config.Env[i] = "PATH=" + value
 			return
 		}
 	}
 
 	// If we get here, we never saw PATH.
-	cf.Config.Env = append(cf.Config.Env, "PATH="+appPath)
+	cf.Config.Env = append(cf.Config.Env, "PATH="+appDir)
 }


Test patch:
diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go
index 55fe51b6..db320481 100644
--- a/pkg/build/gobuild_test.go
+++ b/pkg/build/gobuild_test.go
@@ -341,16 +341,22 @@ func TestGoBuild(t *testing.T) {
 		}
 	})
 
-	// Check that PATH contains the produced binary.
+	// Check that PATH contains the directory of the produced binary.
 	t.Run("check PATH env var", func(t *testing.T) {
 		cfg, err := img.ConfigFile()
 		if err != nil {
 			t.Errorf("ConfigFile() = %v", err)
 		}
 		found := false
-		for _, entry := range cfg.Config.Env {
-			if strings.HasPrefix(entry, "PATH=") && strings.Contains(entry, "/ko-app/test") {
-				found = true
+		for _, envVar := range cfg.Config.Env {
+			if strings.HasPrefix(envVar, "PATH=") {
+				pathValue := strings.TrimPrefix(envVar, "PATH=")
+				pathEntries := strings.Split(pathValue, ":")
+				for _, pathEntry := range pathEntries {
+					if pathEntry == appDir {
+						found = true
+					}
+				}
 			}
 		}
 		if !found {
Repository: dgraph-io/badger
Pull request #322 (2017-11-14 08:55:09)

Don't return deleted/expired values in txn.Get


<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dgraph-io/badger/322)
<!-- Reviewable:end -->


janardhan1993: 



Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion.

---

*[transaction.go, line 297 at r1](https://reviewable.io:443/reviews/dgraph-io/badger/322#-KytjOC8wJgojI53Hjtb:-KytjOC8wJgojI53Hjtc:byyw1ge) ([raw file](https://github.com/dgraph-io/badger/blob/d9d54de5fdda84e6fce444cdf83ca3b5306400c5/transaction.go#L297)):*
> ```Go
> 	if txn.update {
> 		if e, has := txn.pendingWrites[string(key)]; has && bytes.Equal(key, e.Key) {
> 			if e.meta&bitDelete > 0 {
> ```

isdeletedorexpired takes a valuestruct, so can't use that function.

---


*Comments from [Reviewable](https://reviewable.io:443/reviews/dgraph-io/badger/322)*
<!-- Sent from Reviewable.io -->

manishrjain: <img class="emoji" title=":lgtm:" alt=":lgtm:" align="absmiddle" src="https://reviewable.io/lgtm.png" height="20" width="61"/>

---

Reviewed 2 of 2 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion.

---



*Comments from [Reviewable](https://reviewable.io:443/reviews/dgraph-io/badger/322#-:-Kyu3RULQWUJcnM276Sx:bnfp4nl)*
<!-- Sent from Reviewable.io -->


Patch:
diff --git a/transaction.go b/transaction.go
index c1da241..f436c1d 100644
--- a/transaction.go
+++ b/transaction.go
@@ -294,6 +294,12 @@ func (txn *Txn) Get(key []byte) (item *Item, rerr error) {
 	item = new(Item)
 	if txn.update {
 		if e, has := txn.pendingWrites[string(key)]; has && bytes.Equal(key, e.Key) {
+			if e.meta&bitDelete > 0 {
+				return nil, ErrKeyNotFound
+			}
+			if e.ExpiresAt > 0 && e.ExpiresAt <= uint64(time.Now().Unix()) {
+				return nil, ErrKeyNotFound
+			}
 			// Fulfill from cache.
 			item.meta = e.meta
 			item.val = e.Value


Test patch:
diff --git a/db_test.go b/db_test.go
index dee2a84..3912f14 100644
--- a/db_test.go
+++ b/db_test.go
@@ -231,6 +231,29 @@ func TestGet(t *testing.T) {
 	txn.Discard()
 }
 
+func TestGetAfterDelete(t *testing.T) {
+	dir, err := ioutil.TempDir("", "badger")
+	require.NoError(t, err)
+	defer os.RemoveAll(dir)
+	kv, err := Open(getTestOptions(dir))
+	if err != nil {
+		t.Error(err)
+	}
+	defer kv.Close()
+
+	// populate with one entry
+	key := []byte("key")
+	txnSet(t, kv, key, []byte("val1"), 0x00)
+	require.NoError(t, kv.Update(func(txn *Txn) error {
+		err := txn.Delete(key)
+		require.NoError(t, err)
+
+		_, err = txn.Get(key)
+		require.Equal(t, ErrKeyNotFound, err)
+		return nil
+	}))
+}
+
 func TestExists(t *testing.T) {
 	dir, err := ioutil.TempDir("", "badger")
 	require.NoError(t, err)
Repository: dgraph-io/badger
Pull request #406 (2018-01-21 23:39:03)

update commitTs and readts during loading from backup


<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dgraph-io/badger/406)
<!-- Reviewable:end -->



Patch:
diff --git a/backup.go b/backup.go
index 375b5a3..05e8592 100644
--- a/backup.go
+++ b/backup.go
@@ -124,6 +124,11 @@ func (db *DB) Load(r io.Reader) error {
 			UserMeta:  e.UserMeta[0],
 			ExpiresAt: e.ExpiresAt,
 		})
+		// Update nextCommit, memtable stores this timestamp in badger head
+		// when flushed.
+		if e.Version >= db.orc.commitTs() {
+			db.orc.nextCommit = e.Version + 1
+		}
 
 		if len(entries) == 1000 {
 			if err := batchSetAsyncIfNoErr(entries); err != nil {
@@ -145,6 +150,7 @@ func (db *DB) Load(r io.Reader) error {
 	case err := <-errChan:
 		return err
 	default:
+		db.orc.curRead = db.orc.commitTs() - 1
 		return nil
 	}
 }
diff --git a/y/file_dsync.go b/y/file_dsync.go
index bd25c9e..3f3445e 100644
--- a/y/file_dsync.go
+++ b/y/file_dsync.go
@@ -1,4 +1,4 @@
-// +build !dragonfly,!freebsd,!windows,!darwin
+// +build !dragonfly,!freebsd,!windows
 
 /*
  * Copyright 2017 Dgraph Labs, Inc. and Contributors
@@ -18,8 +18,8 @@
 
 package y
 
-import "syscall"
+import "golang.org/x/sys/unix"
 
 func init() {
-	datasyncFileFlag = syscall.O_DSYNC
+	datasyncFileFlag = unix.O_DSYNC
 }
diff --git a/y/file_nodsync.go b/y/file_nodsync.go
index be295f2..b68be7a 100644
--- a/y/file_nodsync.go
+++ b/y/file_nodsync.go
@@ -1,4 +1,4 @@
-// +build dragonfly freebsd windows darwin
+// +build dragonfly freebsd windows
 
 /*
  * Copyright 2017 Dgraph Labs, Inc. and Contributors


Test patch:
diff --git a/backup_test.go b/backup_test.go
index 74755b5..5f4f194 100644
--- a/backup_test.go
+++ b/backup_test.go
@@ -39,20 +39,33 @@ func TestDumpLoad(t *testing.T) {
 		version  uint64
 	}{
 		{key: []byte("answer1"), val: []byte("42"), version: 1},
-		{key: []byte("answer2"), val: []byte("43"), userMeta: 1, version: 1},
+		{key: []byte("answer2"), val: []byte("43"), userMeta: 1, version: 2},
 	}
 
 	err = db.Update(func(txn *Txn) error {
-		for _, e := range entries {
-			err := txn.SetWithMeta(e.key, e.val, e.userMeta)
-			if err != nil {
-				return err
-			}
+		e := entries[0]
+		err := txn.SetWithMeta(e.key, e.val, e.userMeta)
+		if err != nil {
+			return err
 		}
 		return nil
 	})
 	require.NoError(t, err)
 
+	err = db.Update(func(txn *Txn) error {
+		e := entries[1]
+		err := txn.SetWithMeta(e.key, e.val, e.userMeta)
+		if err != nil {
+			return err
+		}
+		return nil
+	})
+	require.NoError(t, err)
+
+	// Use different directory.
+	dir, err = ioutil.TempDir("", "badger")
+	require.NoError(t, err)
+	defer os.RemoveAll(dir)
 	bak, err := ioutil.TempFile(dir, "badgerbak")
 	require.NoError(t, err)
 	ts, err := db.Backup(bak, 0)
@@ -87,6 +100,7 @@ func TestDumpLoad(t *testing.T) {
 			require.Equal(t, entries[count].userMeta, item.UserMeta())
 			count++
 		}
+		require.Equal(t, count, 2)
 		return nil
 	})
 	require.NoError(t, err)