go-billy icon indicating copy to clipboard operation
go-billy copied to clipboard

memfs doesn't handle renaming files which share a prefix (e.g foobar.txt and foobar.txt.asc)

Open gildor478 opened this issue 5 years ago • 0 comments

Whenever I try to rename files that share the same prefix, I get an error "Received unexpected error: file does not exist" on the second file.

I cannot reproduce the same behavior on osfs, which works as expected in this case.

I expect to be able to rename multiple files in a row even if they have part of their name in common.

Here is a test to reproduce the error:

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"gopkg.in/src-d/go-billy.v4/memfs"
)

func TestBilly_memfsRename(t *testing.T) {
	mfs := memfs.New()
	fd, err := mfs.Create("/foobar.txt")
	require.NoError(t, err)
	require.NoError(t, fd.Close())
	fd, err = mfs.Create("/barbaz.txt")
	require.NoError(t, err)
	require.NoError(t, fd.Close())
	fd, err = mfs.Create("/foobar.txt.asc")
	require.NoError(t, err)
	require.NoError(t, fd.Close())

	assert.NoError(t, mfs.Rename("/foobar.txt", "foobar-tmp.txt"))
	assert.NoError(t, mfs.Rename("/barbaz.txt", "barbaz-tmp.txt"))
	assert.NoError(t, mfs.Rename("/foobar.txt.asc", "foobar-tmp.txt.asc"))
}

gildor478 avatar Aug 07 '19 12:08 gildor478