瀏覽代碼

fix truncate test cases on Windows

Nicola Murino 5 年之前
父節點
當前提交
7381a867ba
共有 3 個文件被更改,包括 5 次插入2 次删除
  1. 2 1
      common/connection.go
  2. 1 1
      common/connection_test.go
  3. 2 0
      common/transfer_test.go

+ 2 - 1
common/connection.go

@@ -496,7 +496,8 @@ func (c *BaseConnection) truncateFile(fsPath string, size int64) error {
 	// if we found no transfer we truncate by path.
 	// if we found no transfer we truncate by path.
 	// pkg/sftp should expose an optional interface and call truncate directly on the opened handle ...
 	// pkg/sftp should expose an optional interface and call truncate directly on the opened handle ...
 	// If we try to truncate by path an already opened file we get an error on Windows
 	// If we try to truncate by path an already opened file we get an error on Windows
-	err := c.truncateOpenHandle(fsPath, size)
+	var err error
+	err = c.truncateOpenHandle(fsPath, size)
 	if err == errNoTransfer {
 	if err == errNoTransfer {
 		c.Log(logger.LevelDebug, "file path %#v not found in active transfers, execute trucate by path", fsPath)
 		c.Log(logger.LevelDebug, "file path %#v not found in active transfers, execute trucate by path", fsPath)
 		err = c.Fs.Truncate(fsPath, size)
 		err = c.Fs.Truncate(fsPath, size)

+ 1 - 1
common/connection_test.go

@@ -530,7 +530,7 @@ func TestSetStat(t *testing.T) {
 	})
 	})
 	assert.Error(t, err)
 	assert.Error(t, err)
 	// truncate
 	// truncate
-	err = c.SetStat(filepath.Join(user.GetHomeDir(), "missing"), "/missing", &StatAttributes{
+	err = c.SetStat(filepath.Join(user.GetHomeDir(), "/missing/missing"), "/missing/missing", &StatAttributes{
 		Size:  1,
 		Size:  1,
 		Flags: StatAttrSize,
 		Flags: StatAttrSize,
 	})
 	})

+ 2 - 0
common/transfer_test.go

@@ -106,6 +106,8 @@ func TestTruncate(t *testing.T) {
 	assert.NoError(t, err)
 	assert.NoError(t, err)
 	err = transfer.Close()
 	err = transfer.Close()
 	assert.NoError(t, err)
 	assert.NoError(t, err)
+	err = file.Close()
+	assert.NoError(t, err)
 	fi, err := os.Stat(testFile)
 	fi, err := os.Stat(testFile)
 	if assert.NoError(t, err) {
 	if assert.NoError(t, err) {
 		assert.Equal(t, int64(2), fi.Size())
 		assert.Equal(t, int64(2), fi.Size())