当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Lstat函数代码示例

本文整理汇总了Golang中syscall.Lstat函数的典型用法代码示例。如果您正苦于以下问题:Golang Lstat函数的具体用法?Golang Lstat怎么用?Golang Lstat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Lstat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestStat

func TestStat(t *testing.T) {
	mnt, err := fstestutil.MountedT(t, &NzbFS{"testdb"})
	if err != nil {
		t.Error(err)
	}
	defer mnt.Close()

	var stat syscall.Stat_t
	err = syscall.Lstat(path.Join(mnt.Dir, "hello"), &stat)
	if err != nil {
		t.Error(err)
	}
	if (stat.Mode & syscall.S_IFREG) == 0 {
		t.Error("hello file was not reported as a file")
	}

	err = syscall.Lstat(path.Join(mnt.Dir, "noexist"), &stat)
	if err == nil {
		t.Error("Should have failed on nonexistant file")
	}

	err = syscall.Lstat(path.Join(mnt.Dir, "foo"), &stat)
	if err != nil {
		t.Error(err)
	}
	if (stat.Mode & syscall.S_IFDIR) == 0 {
		t.Error("foo directory was not reported as a directory")
	}
}
开发者ID:nzbfs,项目名称:go-nzbfs,代码行数:29,代码来源:fs_test.go

示例2: TestLinkExisting

// Deal correctly with hard links implied by matching client inode
// numbers.
func TestLinkExisting(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Cleanup()

	c := RandomData(5)

	err := ioutil.WriteFile(tc.orig+"/file1", c, 0644)
	CheckSuccess(err)
	err = os.Link(tc.orig+"/file1", tc.orig+"/file2")
	CheckSuccess(err)

	var s1, s2 syscall.Stat_t
	err = syscall.Lstat(tc.mnt+"/file1", &s1)
	CheckSuccess(err)
	err = syscall.Lstat(tc.mnt+"/file2", &s2)
	CheckSuccess(err)

	if s1.Ino != s2.Ino {
		t.Errorf("linked files should have identical inodes %v %v", s1.Ino, s2.Ino)
	}

	back, err := ioutil.ReadFile(tc.mnt + "/file1")
	CheckSuccess(err)
	CompareSlices(t, back, c)
}
开发者ID:niltonkummer,项目名称:go-fuse,代码行数:27,代码来源:loopback_test.go

示例3: TestLinkForget

// Deal correctly with hard links implied by matching client inode
// numbers.
func TestLinkForget(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Cleanup()

	c := "hello"

	err := ioutil.WriteFile(tc.orig+"/file1", []byte(c), 0644)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	err = os.Link(tc.orig+"/file1", tc.orig+"/file2")
	if err != nil {
		t.Fatalf("Link failed: %v", err)
	}

	var s1, s2 syscall.Stat_t
	err = syscall.Lstat(tc.mnt+"/file1", &s1)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}

	tc.pathFs.ForgetClientInodes()

	err = syscall.Lstat(tc.mnt+"/file2", &s2)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}
	if s1.Ino == s2.Ino {
		t.Error("After forget, we should not export links")
	}
}
开发者ID:seacoastboy,项目名称:go-fuse,代码行数:33,代码来源:loopback_test.go

示例4: TestMemUnionFsCopyChmod

func TestMemUnionFsCopyChmod(t *testing.T) {
	wd, _, clean := setupMemUfs(t)
	defer clean()

	contents := "hello"
	fn := wd + "/mnt/y"
	err := ioutil.WriteFile(fn, []byte(contents), 0644)
	CheckSuccess(err)

	err = os.Chmod(fn, 0755)
	CheckSuccess(err)

	st := syscall.Stat_t{}
	err = syscall.Lstat(fn, &st)
	CheckSuccess(err)
	if st.Mode&0111 == 0 {
		t.Errorf("1st attr error %o", st.Mode)
	}
	time.Sleep(entryTtl * 11 / 10)
	err = syscall.Lstat(fn, &st)
	CheckSuccess(err)
	if st.Mode&0111 == 0 {
		t.Errorf("uncached attr error %o", st.Mode)
	}
}
开发者ID:janneke,项目名称:termite,代码行数:25,代码来源:memunionfs_test.go

示例5: TestMemUnionFsLink

func TestMemUnionFsLink(t *testing.T) {
	wd, _, clean := setupMemUfs(t)
	defer clean()

	content := "blabla"
	fn := wd + "/ro/file"
	err := ioutil.WriteFile(fn, []byte(content), 0666)
	CheckSuccess(err)

	err = os.Link(wd+"/mnt/file", wd+"/mnt/linked")
	CheckSuccess(err)

	var st2 syscall.Stat_t
	err = syscall.Lstat(wd+"/mnt/linked", &st2)
	CheckSuccess(err)

	var st1 syscall.Stat_t
	err = syscall.Lstat(wd+"/mnt/file", &st1)
	CheckSuccess(err)

	if st1.Ino != st2.Ino {
		t.Errorf("inode numbers should be equal for linked files %v, %v", st1.Ino, st2.Ino)
	}
	c, err := ioutil.ReadFile(wd + "/mnt/linked")
	if string(c) != content {
		t.Errorf("content mismatch got %q want %q", string(c), content)
	}
}
开发者ID:janneke,项目名称:termite,代码行数:28,代码来源:memunionfs_test.go

示例6: TestLinkExisting

// Deal correctly with hard links implied by matching client inode
// numbers.
func TestLinkExisting(t *testing.T) {
	me := NewTestCase(t)
	defer me.Cleanup()

	c := "hello"

	err := ioutil.WriteFile(me.orig+"/file1", []byte(c), 0644)
	CheckSuccess(err)
	err = os.Link(me.orig+"/file1", me.orig+"/file2")
	CheckSuccess(err)

	var s1, s2 syscall.Stat_t
	err = syscall.Lstat(me.mnt+"/file1", &s1)
	CheckSuccess(err)
	err = syscall.Lstat(me.mnt+"/file2", &s2)
	CheckSuccess(err)

	if s1.Ino != s2.Ino {
		t.Errorf("linked files should have identical inodes %v %v", s1.Ino, s2.Ino)
	}

	c1, err := ioutil.ReadFile(me.mnt + "/file1")
	CheckSuccess(err)
	if string(c1) != c {
		t.Errorf("Content mismatch relative to original.")
	}
}
开发者ID:mdwrigh2,项目名称:go-fuse,代码行数:29,代码来源:loopback_test.go

示例7: TestLinkExisting

// Deal correctly with hard links implied by matching client inode
// numbers.
func TestLinkExisting(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Cleanup()

	c := RandomData(5)

	err := ioutil.WriteFile(tc.orig+"/file1", c, 0644)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	err = os.Link(tc.orig+"/file1", tc.orig+"/file2")
	if err != nil {
		t.Fatalf("Link failed: %v", err)
	}

	var s1, s2 syscall.Stat_t
	err = syscall.Lstat(tc.mnt+"/file1", &s1)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}
	err = syscall.Lstat(tc.mnt+"/file2", &s2)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}

	if s1.Ino != s2.Ino {
		t.Errorf("linked files should have identical inodes %v %v", s1.Ino, s2.Ino)
	}

	back, err := ioutil.ReadFile(tc.mnt + "/file1")
	if err != nil {
		t.Fatalf("ReadFile failed: %v", err)
	}
	CompareSlices(t, back, c)
}
开发者ID:seacoastboy,项目名称:go-fuse,代码行数:37,代码来源:loopback_test.go

示例8: TestLinkCreate

func TestLinkCreate(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Cleanup()

	content := RandomData(125)
	err := ioutil.WriteFile(tc.origFile, content, 0700)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	err = os.Mkdir(tc.origSubdir, 0777)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	// Link.
	mountSubfile := filepath.Join(tc.mountSubdir, "subfile")
	err = os.Link(tc.mountFile, mountSubfile)
	if err != nil {
		t.Fatalf("Link failed: %v", err)
	}

	var subStat, stat syscall.Stat_t
	err = syscall.Lstat(mountSubfile, &subStat)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}
	err = syscall.Lstat(tc.mountFile, &stat)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}

	if stat.Nlink != 2 {
		t.Errorf("Expect 2 links: %v", stat)
	}
	if stat.Ino != subStat.Ino {
		t.Errorf("Link succeeded, but inode numbers different: %v %v", stat.Ino, subStat.Ino)
	}
	readback, err := ioutil.ReadFile(mountSubfile)
	if err != nil {
		t.Fatalf("ReadFile failed: %v", err)
	}
	CompareSlices(t, readback, content)

	err = os.Remove(tc.mountFile)
	if err != nil {
		t.Fatalf("Remove failed: %v", err)
	}

	_, err = ioutil.ReadFile(mountSubfile)
	if err != nil {
		t.Fatalf("ReadFile failed: %v", err)
	}
}
开发者ID:seacoastboy,项目名称:go-fuse,代码行数:53,代码来源:loopback_test.go

示例9: TestLinkForget

// Deal correctly with hard links implied by matching client inode
// numbers.
func TestLinkForget(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Cleanup()

	c := "hello"

	tc.WriteFile(tc.orig+"/file1", []byte(c), 0644)
	err := os.Link(tc.orig+"/file1", tc.orig+"/file2")
	if err != nil {
		t.Fatalf("Link failed: %v", err)
	}

	for _, fn := range []string{"file1", "file2"} {
		var s syscall.Stat_t
		err = syscall.Lstat(tc.mnt+"/"+fn, &s)
		if err != nil {
			t.Fatalf("Lstat failed: %v", err)
		}
		tc.pathFs.ForgetClientInodes()
	}

	// Now, the backing files are still hardlinked, but go-fuse's
	// view of them should not be because of the
	// ForgetClientInodes call. To prove this, we swap out the
	// files in the backing store, and prove that they are
	// distinct by truncating to different lengths.
	for _, fn := range []string{"file1", "file2"} {
		fn = tc.orig + "/" + fn
		if err := os.Remove(fn); err != nil {
			t.Fatalf("Remove", err)
		}
		tc.WriteFile(fn, []byte(c), 0644)
	}
	for i, fn := range []string{"file1", "file2"} {
		fn = tc.mnt + "/" + fn
		if err := os.Truncate(fn, int64(i)); err != nil {
			t.Fatalf("Truncate", err)
		}
	}

	for i, fn := range []string{"file1", "file2"} {
		var s syscall.Stat_t
		err = syscall.Lstat(tc.mnt+"/"+fn, &s)
		if err != nil {
			t.Fatalf("Lstat failed: %v", err)
		}
		if s.Size != int64(i) {
			t.Errorf("Lstat(%q): got size %d, want %d", fn, s.Size, i)
		}
	}
}
开发者ID:Richardphp,项目名称:noms,代码行数:53,代码来源:loopback_test.go

示例10: TestFromStatT

// TestFromStatT tests fromStatT for a tempfile
func TestFromStatT(t *testing.T) {
	file, _, _, dir := prepareFiles(t)
	defer os.RemoveAll(dir)

	stat := &syscall.Stat_t{}
	err := syscall.Lstat(file, stat)

	s, err := fromStatT(stat)
	if err != nil {
		t.Fatal(err)
	}

	if stat.Mode != s.Mode() {
		t.Fatal("got invalid mode")
	}
	if stat.Uid != s.UID() {
		t.Fatal("got invalid uid")
	}
	if stat.Gid != s.Gid() {
		t.Fatal("got invalid gid")
	}
	if stat.Rdev != s.Rdev() {
		t.Fatal("got invalid rdev")
	}
	if stat.Mtim != s.Mtim() {
		t.Fatal("got invalid mtim")
	}
}
开发者ID:nixuw,项目名称:docker,代码行数:29,代码来源:stat_unix_test.go

示例11: unlink

func (file *File) unlink() error {

	// Remove whatever was there.
	// NOTE: We will generally require the
	// write lock to be held for this routine.

	if file.write_deleted {
		err := cleardelattr(file.write_path)
		if err != nil {
			return err
		}
	}

	var stat syscall.Stat_t
	err := syscall.Lstat(file.write_path, &stat)
	if err == nil {
		if stat.Mode&syscall.S_IFDIR != 0 {
			err = syscall.Rmdir(file.write_path)
			if err != nil {
				return err
			}
		} else {
			err = syscall.Unlink(file.write_path)
			if err != nil {
				return err
			}
		}
	}

	file.write_exists = false
	file.write_deleted = false

	return nil
}
开发者ID:XenServerBestPractice,项目名称:novm,代码行数:34,代码来源:file.go

示例12: TestMemUnionResetDelete

func TestMemUnionResetDelete(t *testing.T) {
	wd, ufs, clean := setupMemUfs(t)
	defer clean()
	ioutil.WriteFile(wd+"/ro/todelete", []byte{42}, 0644)

	var before, after, afterReset syscall.Stat_t
	syscall.Lstat(wd+"/mnt/todelete", &before)
	before.Ino = 0
	os.Remove(wd + "/mnt/todelete")
	syscall.Lstat(wd+"/mnt/todelete", &after)
	testEq(t, after, before, false)
	ufs.Reset()
	syscall.Lstat(wd+"/mnt/todelete", &afterReset)
	afterReset.Ino = 0
	testEq(t, afterReset, before, true)
}
开发者ID:janneke,项目名称:termite,代码行数:16,代码来源:memunionfs_test.go

示例13: TestTouch

func TestTouch(t *testing.T) {
	ts := NewTestCase(t)
	defer ts.Cleanup()

	contents := []byte{1, 2, 3}
	err := ioutil.WriteFile(ts.origFile, []byte(contents), 0700)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	err = os.Chtimes(ts.mountFile, time.Unix(42, 0), time.Unix(43, 0))
	if err != nil {
		t.Fatalf("Chtimes failed: %v", err)
	}

	var stat syscall.Stat_t
	err = syscall.Lstat(ts.mountFile, &stat)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}
	if stat.Atim.Sec != 42 {
		t.Errorf("Got atime.sec %d, want 42. Stat_t was %#v", stat.Atim.Sec, stat)
	}
	if stat.Mtim.Sec != 43 {
		t.Errorf("Got mtime.sec %d, want 43. Stat_t was %#v", stat.Mtim.Sec, stat)
	}
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:26,代码来源:loopback_linux_test.go

示例14: TestNegativeTime

func TestNegativeTime(t *testing.T) {
	ts := NewTestCase(t)
	defer ts.Cleanup()

	_, err := os.Create(ts.origFile)
	if err != nil {
		t.Fatalf("Create failed: %v", err)
	}

	var stat syscall.Stat_t

	// set negative nanosecond will occur errors on UtimesNano as invalid argument
	ut := time.Date(1960, time.January, 10, 23, 0, 0, 0, time.UTC)
	tim := []syscall.Timespec{
		syscall.NsecToTimespec(ut.UnixNano()),
		syscall.NsecToTimespec(ut.UnixNano()),
	}
	err = syscall.UtimesNano(ts.mountFile, tim)
	if err != nil {
		t.Fatalf("UtimesNano failed: %v", err)
	}
	err = syscall.Lstat(ts.mountFile, &stat)
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}

	if stat.Atim.Sec >= 0 || stat.Mtim.Sec >= 0 {
		t.Errorf("Got wrong timestamps %v", stat)
	}
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:30,代码来源:loopback_linux_test.go

示例15: scanDirectory

func (imdb *ImageDataBase) scanDirectory(dirname string) error {
	file, err := os.Open(path.Join(imdb.baseDir, dirname))
	if err != nil {
		return err
	}
	names, err := file.Readdirnames(-1)
	file.Close()
	for _, name := range names {
		filename := path.Join(dirname, name)
		var stat syscall.Stat_t
		err := syscall.Lstat(path.Join(imdb.baseDir, filename), &stat)
		if err != nil {
			if err == syscall.ENOENT {
				continue
			}
			return err
		}
		if stat.Mode&syscall.S_IFMT == syscall.S_IFDIR {
			err = imdb.scanDirectory(filename)
		} else if stat.Mode&syscall.S_IFMT == syscall.S_IFREG {
			err = imdb.loadFile(filename)
		}
		if err != nil {
			if err == syscall.ENOENT {
				continue
			}
			return err
		}
	}
	return nil
}
开发者ID:datatonic,项目名称:Dominator,代码行数:31,代码来源:load.go


注:本文中的syscall.Lstat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。