nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pkg/sftp
Pull request #316 (2019-10-27 06:05:33)

Fix posixrename and add a test case
I extracted the relevant parts from https://github.com/pkg/sftp/pull/313 keeping the author and added a test case


Patch:
diff --git a/request-server.go b/request-server.go
index 7b03dbb..d15f3a1 100644
--- a/request-server.go
+++ b/request-server.go
@@ -190,15 +190,10 @@ func (rs *RequestServer) packetWorker(
 				request = NewRequest("Stat", request.Filepath)
 				rpkt = request.call(rs.Handlers, pkt)
 			}
-		case *sshFxpExtendedPacket:
-			switch expkt := pkt.SpecificPacket.(type) {
-			default:
-				rpkt = statusFromError(pkt, ErrSSHFxOpUnsupported)
-			case *sshFxpExtendedPacketPosixRename:
-				request := NewRequest("Rename", expkt.Oldpath)
-				request.Target = expkt.Newpath
-				rpkt = request.call(rs.Handlers, pkt)
-			}
+		case *sshFxpExtendedPacketPosixRename:
+			request := NewRequest("Rename", pkt.Oldpath)
+			request.Target = pkt.Newpath
+			rpkt = request.call(rs.Handlers, pkt)
 		case hasHandle:
 			handle := pkt.getHandle()
 			request, ok := rs.getRequest(handle)


Test patch:
diff --git a/request-server_test.go b/request-server_test.go
index 29c48c9..6f06bd2 100644
--- a/request-server_test.go
+++ b/request-server_test.go
@@ -241,10 +241,21 @@ func TestRequestRename(t *testing.T) {
 	err = p.cli.Rename("/foo", "/bar")
 	assert.Nil(t, err)
 	f, err := r.fetch("/bar")
+	if err != nil {
+		t.Fatal("unexpected error:", err)
+	}
 	assert.Equal(t, "bar", f.Name())
-	assert.Nil(t, err)
 	_, err = r.fetch("/foo")
 	assert.Equal(t, os.ErrNotExist, err)
+	err = p.cli.PosixRename("/bar", "/baz")
+	assert.Nil(t, err)
+	f, err = r.fetch("/baz")
+	if err != nil {
+		t.Fatal("unexpected error:", err)
+	}
+	assert.Equal(t, "baz", f.Name())
+	_, err = r.fetch("/bar")
+	assert.Equal(t, os.ErrNotExist, err)
 }
 
 func TestRequestRenameFail(t *testing.T) {