本文整理汇总了Golang中syscall.Rmdir函数的典型用法代码示例。如果您正苦于以下问题:Golang Rmdir函数的具体用法?Golang Rmdir怎么用?Golang Rmdir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rmdir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Remove
func (c *Cgroups) Remove(name string) error {
errCpu := syscall.Rmdir(c.cpuacct + "/" + name)
errMemory := syscall.Rmdir(c.memory + "/" + name)
if errCpu != nil && errMemory != nil {
return errCpu
}
return nil
}
示例2: TestMkdirRmdir
// TestMkdirRmdir creates and deletes a directory
func TestMkdirRmdir(t *testing.T, plainDir string) {
dir := plainDir + "/dir1"
err := os.Mkdir(dir, 0777)
if err != nil {
t.Error(err)
return
}
err = syscall.Rmdir(dir)
if err != nil {
t.Error(err)
return
}
// Removing a non-empty dir should fail with ENOTEMPTY
if os.Mkdir(dir, 0777) != nil {
t.Error(err)
return
}
f, err := os.Create(dir + "/file")
if err != nil {
t.Error(err)
return
}
f.Close()
err = syscall.Rmdir(dir)
errno := err.(syscall.Errno)
if errno != syscall.ENOTEMPTY {
t.Errorf("Should have gotten ENOTEMPTY, go %v", errno)
}
if syscall.Unlink(dir+"/file") != nil {
t.Error(err)
return
}
if syscall.Rmdir(dir) != nil {
t.Error(err)
return
}
// We should also be able to remove a directory we do not have permissions to
// read or write
err = os.Mkdir(dir, 0000)
if err != nil {
t.Error(err)
return
}
err = syscall.Rmdir(dir)
if err != nil {
// Make sure the directory can cleaned up by the next test run
os.Chmod(dir, 0700)
t.Error(err)
return
}
}
示例3: Delete
func (fs *FS) Delete(id string) error {
//dn := fs.of_id(id)
a, b, c, d := SplitFN(id)
an := fs.Prefix + "/" + a
bn := an + "/" + b
cn := bn + "/" + c
dn := cn + "/" + d
e := os.RemoveAll(dn)
if e == nil {
syscall.Rmdir(cn)
syscall.Rmdir(bn)
syscall.Rmdir(an)
}
return e
}
示例4: TestWriteFilePermissions
func TestWriteFilePermissions(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer syscall.Rmdir(dir)
fullPath := path.Join(dir, "tmp", "foo")
wf := File{
Path: fullPath,
RawFilePermissions: "0755",
}
if err := WriteFile(&wf); err != nil {
t.Fatalf("Processing of WriteFile failed: %v", err)
}
fi, err := os.Stat(fullPath)
if err != nil {
t.Fatalf("Unable to stat file: %v", err)
}
if fi.Mode() != os.FileMode(0755) {
t.Errorf("File has incorrect mode: %v", fi.Mode())
}
}
示例5: 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
}
示例6: Remove
// Remove removes the named file or directory.
// If there is an error, it will be of type *PathError.
func Remove(name string) error {
// System call interface forces us to know
// whether name is a file or directory.
// Try both: it is cheaper on average than
// doing a Stat plus the right one.
e := syscall.Unlink(name)
if e == nil {
return nil
}
e1 := syscall.Rmdir(name)
if e1 == nil {
return nil
}
// Both failed: figure out which error to return.
// OS X and Linux differ on whether unlink(dir)
// returns EISDIR, so can't use that. However,
// both agree that rmdir(file) returns ENOTDIR,
// so we can use that to decide which error is real.
// Rmdir might also return ENOTDIR if given a bad
// file path, like /etc/passwd/foo, but in that case,
// both errors will be ENOTDIR, so it's okay to
// use the error from unlink.
if e1 != syscall.ENOTDIR {
e = e1
}
return &PathError{"remove", name, e}
}
示例7: cmd_rmdir
func cmd_rmdir(cmd *Interpreter) (ErrorLevel, error) {
if len(cmd.Args) <= 1 {
fmt.Println("Usage: rmdir [/s] DIRECTORIES...")
return NOERROR, nil
}
s_option := false
message := "%s: Rmdir Are you sure? [Yes/No/Quit] "
errorcount := ErrorLevel(0)
for _, arg1 := range cmd.Args[1:] {
if arg1 == "/s" {
s_option = true
message = "%s : Delete Tree. Are you sure? [Yes/No/Quit] "
continue
}
stat, statErr := os.Lstat(arg1)
if statErr != nil {
fmt.Fprintf(cmd.Stderr, "%s: %s\n", arg1, statErr)
errorcount++
continue
}
if !stat.IsDir() {
fmt.Fprintf(cmd.Stderr, "%s: not directory\n", arg1)
errorcount++
continue
}
fmt.Fprintf(cmd.Stderr, message, arg1)
ch := conio.GetCh()
fmt.Fprintf(cmd.Stderr, "%c ", ch)
switch ch {
case 'y', 'Y':
case 'q', 'Q':
fmt.Fprintln(cmd.Stderr, "-> canceled all")
return errorcount, nil
default:
fmt.Fprintln(cmd.Stderr, "-> canceled")
continue
}
var err error
if s_option {
fmt.Fprintln(cmd.Stdout)
err = dos.Truncate(arg1, func(path string, err error) bool {
fmt.Fprintf(cmd.Stderr, "%s -> %s\n", path, err.Error())
return true
}, cmd.Stdout)
} else {
err = syscall.Rmdir(arg1)
}
if err != nil {
fmt.Fprintf(cmd.Stderr, "-> %s\n", err.Error())
errorcount++
} else {
fmt.Fprintln(cmd.Stderr, "-> done.")
}
}
return errorcount, nil
}
示例8: testMkdirRmdir
// Create and delete a directory
func testMkdirRmdir(t *testing.T, plainDir string) {
dir := plainDir + "dir1"
err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)
}
err = syscall.Rmdir(dir)
if err != nil {
t.Fatal(err)
}
// Removing a non-empty dir should fail with ENOTEMPTY
if os.Mkdir(dir, 0777) != nil {
t.Fatal(err)
}
f, err := os.Create(dir + "/file")
if err != nil {
t.Fatal(err)
}
f.Close()
err = syscall.Rmdir(dir)
errno := err.(syscall.Errno)
if errno != syscall.ENOTEMPTY {
t.Errorf("Should have gotten ENOTEMPTY, go %v", errno)
}
if syscall.Unlink(dir+"/file") != nil {
t.Fatal(err)
}
if syscall.Rmdir(dir) != nil {
t.Fatal(err)
}
// We should also be able to remove a directory we do not have permissions to
// read or write
err = os.Mkdir(dir, 0000)
if err != nil {
t.Fatal(err)
}
err = syscall.Rmdir(dir)
if err != nil {
t.Fatal(err)
}
}
示例9: Rmdir
func (constor *Constor) Rmdir(header *fuse.InHeader, name string) (code fuse.Status) {
constor.log("%d %s", header.NodeId, name)
var stat syscall.Stat_t
parentino := header.NodeId
dirpath, err := constor.dentrymap.getPath(parentino)
if err != nil {
return fuse.ToStatus(err)
}
path := Path.Join(dirpath, name)
if err := constor.Lstat(path, &stat); err != nil {
return fuse.ToStatus(err)
}
li := constor.getLayer(path)
if li == -1 {
return fuse.EIO
}
pathlayer0 := Path.Join(constor.layers[0], path)
if li == 0 {
// FIXME: make sure the dir is not empty
// err = os.RemoveAll(pathlayer0)
err = syscall.Rmdir(pathlayer0)
if err != nil {
return fuse.ToStatus(err)
}
li = constor.getLayer(path)
}
if li > 0 {
err := constor.createPath(dirpath)
if err != nil {
return fuse.ToStatus(err)
}
fd, err := syscall.Creat(pathlayer0, 0)
if err != nil {
return fuse.ToStatus(err)
}
syscall.Close(fd)
err = constor.setdeleted(pathlayer0)
if err != nil {
return fuse.ToStatus(err)
}
}
dentry, err := constor.dentrymap.findDentry(parentino, stat.Ino)
if err != nil {
return fuse.ToStatus(err)
}
constor.dentrymap.unhashDentry(dentry)
return fuse.OK
}
示例10: TestWriteFileInvalidPermission
func TestWriteFileInvalidPermission(t *testing.T) {
wf := WriteFile{
Path: "/tmp/foo",
Content: "bar",
Permissions: "pants",
}
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer syscall.Rmdir(dir)
if err := ProcessWriteFile(dir, &wf); err == nil {
t.Fatalf("Expected error to be raised when writing file with invalid permission")
}
}
示例11: TestPlaceNetworkUnit
func TestPlaceNetworkUnit(t *testing.T) {
u := Unit{
Name: "50-eth0.network",
Runtime: true,
Content: `[Match]
Name=eth47
[Network]
Address=10.209.171.177/19
`,
}
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer syscall.Rmdir(dir)
if _, err := PlaceUnit(dir, &u); err != nil {
t.Fatalf("PlaceUnit failed: %v", err)
}
fullPath := path.Join(dir, "run", "systemd", "network", "50-eth0.network")
fi, err := os.Stat(fullPath)
if err != nil {
t.Fatalf("Unable to stat file: %v", err)
}
if fi.Mode() != os.FileMode(0644) {
t.Errorf("File has incorrect mode: %v", fi.Mode())
}
contents, err := ioutil.ReadFile(fullPath)
if err != nil {
t.Fatalf("Unable to read expected file: %v", err)
}
expect := `[Match]
Name=eth47
[Network]
Address=10.209.171.177/19
`
if string(contents) != expect {
t.Fatalf("File has incorrect contents '%s'.\nExpected '%s'", string(contents), expect)
}
}
示例12: Mkdir
func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fuse.Status) {
if fs.isFiltered(relPath) {
return fuse.EPERM
}
encPath, err := fs.getBackingPath(relPath)
if err != nil {
return fuse.ToStatus(err)
}
if !fs.args.DirIV {
return fuse.ToStatus(os.Mkdir(encPath, os.FileMode(mode)))
}
// We need write and execute permissions to create gocryptfs.diriv
origMode := mode
mode = mode | 0300
// The new directory may take the place of an older one that is still in the cache
fs.CryptFS.DirIVCacheEnc.Clear()
// Create directory
fs.dirIVLock.Lock()
defer fs.dirIVLock.Unlock()
err = os.Mkdir(encPath, os.FileMode(mode))
if err != nil {
return fuse.ToStatus(err)
}
// Create gocryptfs.diriv inside
err = cryptfs.WriteDirIV(encPath)
if err != nil {
// This should not happen
cryptfs.Warn.Printf("Mkdir: WriteDirIV failed: %v", err)
err2 := syscall.Rmdir(encPath)
if err2 != nil {
cryptfs.Warn.Printf("Mkdir: Rmdir rollback failed: %v", err2)
}
return fuse.ToStatus(err)
}
// Set permissions back to what the user wanted
if origMode != mode {
err = os.Chmod(encPath, os.FileMode(origMode))
if err != nil {
cryptfs.Warn.Printf("Mkdir: Chmod failed: %v", err)
}
}
return fuse.OK
}
示例13: TestWriteFileEncodedContent
func TestWriteFileEncodedContent(t *testing.T) {
wf := WriteFile{
Path: "/tmp/foo",
Content: "",
Encoding: "base64",
}
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer syscall.Rmdir(dir)
if err := ProcessWriteFile(dir, &wf); err == nil {
t.Fatalf("Expected error to be raised when writing file with encoding")
}
}
示例14: TestWriteFileInvalidPermission
func TestWriteFileInvalidPermission(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil {
t.Fatalf("Unable to create tempdir: %v", err)
}
defer syscall.Rmdir(dir)
wf := File{
Path: path.Join(dir, "tmp", "foo"),
Content: "bar",
RawFilePermissions: "pants",
}
if err := WriteFile(&wf); err == nil {
t.Fatalf("Expected error to be raised when writing file with invalid permission")
}
}
示例15: cmd_rmdir
func cmd_rmdir(cmd *interpreter.Interpreter) (interpreter.NextT, error) {
if len(cmd.Args) <= 1 {
fmt.Println("Usage: rmdir [/s] DIRECTORIES...")
return interpreter.CONTINUE, nil
}
s_option := false
message := "%s: Rmdir Are you sure? [Yes/No/Quit] "
for _, arg1 := range cmd.Args[1:] {
if arg1 == "/s" {
s_option = true
message = "%s : Delete Tree. Are you sure? [Yes/No/Quit] "
continue
}
fmt.Fprintf(cmd.Stderr, message, arg1)
ch := conio.GetCh()
fmt.Fprintf(cmd.Stderr, "%c ", ch)
switch ch {
case 'y', 'Y':
case 'q', 'Q':
fmt.Fprintln(cmd.Stderr, "-> canceled all")
return interpreter.CONTINUE, nil
default:
fmt.Fprintln(cmd.Stderr, "-> canceled")
continue
}
var err error
if s_option {
fmt.Fprintln(cmd.Stdout)
err = dos.Truncate(arg1, func(path string, err error) bool {
fmt.Fprintf(cmd.Stderr, "%s -> %s\n", path, err.Error())
return true
}, cmd.Stdout)
} else {
err = syscall.Rmdir(arg1)
}
if err != nil {
fmt.Fprintf(cmd.Stderr, "-> %s\n", err.Error())
} else {
fmt.Fprintln(cmd.Stderr, "-> done.")
}
}
return interpreter.CONTINUE, nil
}