Esempio n. 1
0
func TestRename(t *testing.T) {
	oldname := "test-rename-old"
	newname := "test-rename-new"
	oldpath := filepath.Join(TEST_MOUNTPOINT, oldname)
	newpath := filepath.Join(TEST_MOUNTPOINT, newname)

	c := getContext()

	var stat fuse.Status
	_, stat = fs.Create(oldpath, uint32(os.O_CREATE), 0644, c)
	if !stat.Ok() {
		t.Errorf("Rename fail")
	}

	_, stat = fs.GetAttr(oldpath, c)
	if !stat.Ok() {
		t.Errorf("Rename fail(GetAttr for oldpath after rename)")
	}

	stat = fs.Rename(oldpath, newpath, c)
	if !stat.Ok() {
		t.Errorf("Rename fail(Rename)")
	}

	_, stat = fs.GetAttr(newpath, c)
	if !stat.Ok() { // newpath should be OK
		t.Errorf("Rename fail(GetAttr for newpath)")
	}

	_, stat = fs.GetAttr(oldpath, c)
	if stat != fuse.ENOENT { // oldpath should be ENOENT
		t.Errorf("Rename fail(GetAttr for oldpath")
	}
}
Esempio n. 2
0
func TestOpen(t *testing.T) {
	name := "test-open"
	path := filepath.Join(TEST_MOUNTPOINT, name)
	c := getContext()

	var stat fuse.Status
	_, stat = fs.Create(path, uint32(os.O_CREATE), 0644, c)
	if !stat.Ok() {
		t.Errorf("Open fail")
	}

	_, stat = fs.GetAttr(path, c)
	if !stat.Ok() {
		t.Errorf("Open fail(GetAttr)")
	}
}
Esempio n. 3
0
func TestUnlink(t *testing.T) {
	name := "test-unlink"
	path := filepath.Join(TEST_MOUNTPOINT, name)
	c := getContext()

	var stat fuse.Status
	_, stat = fs.Create(path, uint32(os.O_CREATE), 0644, c)
	if !stat.Ok() {
		t.Errorf("Unlink fail(Create)")
	}

	_, stat = fs.GetAttr(path, c)
	if !stat.Ok() {
		t.Errorf("Unlink fail(GetAttr1)")
	}

	stat = fs.Unlink(path, c)
	if !stat.Ok() {
		t.Errorf("Unlink fail(GetAttr1)")
	}

	_, stat = fs.GetAttr(path, c)
	if stat != fuse.ENOENT {
		t.Errorf("Unlink fail(status is not ENOENT)")
	}
}
Esempio n. 4
0
// GetAttr - FUSE call
func (rfs *ReverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
	if rfs.isTranslatedConfig(relPath) {
		return rfs.inoAwareStat(configfile.ConfReverseName)
	}
	// Handle virtual files
	var f nodefs.File
	var status fuse.Status
	virtual := false
	if rfs.isDirIV(relPath) {
		virtual = true
		f, status = rfs.newDirIVFile(relPath)
	}
	if rfs.isNameFile(relPath) {
		virtual = true
		f, status = rfs.newNameFile(relPath)
	}
	if virtual {
		if !status.Ok() {
			fmt.Printf("GetAttr %q: newXFile failed: %v\n", relPath, status)
			return nil, status
		}
		var a fuse.Attr
		status = f.GetAttr(&a)
		return &a, status
	}

	cPath, err := rfs.decryptPath(relPath)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	a, status := rfs.inoAwareStat(cPath)
	if !status.Ok() {
		return nil, status
	}
	// Calculate encrypted file size
	if a.IsRegular() {
		a.Size = rfs.contentEnc.PlainSizeToCipherSize(a.Size)
	}
	return a, fuse.OK
}
Esempio n. 5
0
// OldNewCaseMatchingRetry is similar to CaseMatchingRetry, but attempts case
// matching on oldName, and parent case matching on newName.
func (fs *FS) OldNewCaseMatchingRetry(oldName, newName string, op func(string, string) bool) {

	if !op(oldName, newName) {
		return
	}

	var code fuse.Status

	// We need oldName to exist.
	if _, err := os.Stat(oldName); err != nil {
		if os.IsNotExist(err) {
			oldName, code = fs.MatchAndLogIcasePath(oldName)
			if !code.Ok() {
				return
			}
		} else {
			return
		}
	}

	// We need the parent of newName to exist.
	if parentNewName, _ := pathSplit(newName); parentNewName != "" {
		if _, err := os.Stat(parentNewName); err != nil {
			if os.IsNotExist(err) {
				newName, code = fs.ParentMatchAndLogIcasePath(newName)
				if !code.Ok() {
					return
				}
			} else {
				return
			}
		}
	}

	op(oldName, newName)
}
Esempio n. 6
0
func assertStatusOk(t *testing.T, status fuse.Status) {
	assert.True(t, status.Ok(), "Expected status to be Ok, was %s", status)
}