Skip to content

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

@gildor478

Description

@gildor478

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"))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions