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


Golang syscall.Unlink函数代码示例

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


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

示例1: Restore

// Restore is used to restore an FSM from a snapshot. It is not called
// concurrently with any other command. The FSM must discard all previous
// state.
// Note, this command is called concurrently with open read txns, so we handle that
func (f *flotillaState) Restore(in io.ReadCloser) error {
	// stream to filePath.tmp
	tempData := f.tempPath + "/data.mdb"
	_ = os.Remove(tempData)
	tempFile, err := os.Create(tempData)
	if err != nil {
		return err
	}
	defer tempFile.Close()
	if _, err = io.Copy(tempFile, in); err != nil {
		return err
	}
	// unlink existing DB and move new one into place
	// can't atomically rename directories so have to lock for this
	f.l.Lock()
	defer f.l.Unlock()
	if err = syscall.Unlink(f.dataPath + "/data.mdb"); err != nil {
		return err
	}
	if err = syscall.Unlink(f.dataPath + "/lock.mdb"); err != nil {
		return err
	}
	if err = os.Rename(tempData, f.dataPath+"/data.mdb"); err != nil {
		return err
	}
	// mark existing env as closeable when all outstanding txns finish
	// posix holds onto our data until we release FD
	f.env.Close()
	// re-initialize env
	f.env, err = newenv(f.dataPath)
	return err
}
开发者ID:jbooth,项目名称:flotilla,代码行数:36,代码来源:statemachine.go

示例2: main

func main() {
	fd, fd_err := syscall.Open(LOCK_PATH, syscall.O_CREAT, 0)
	if fd_err != nil {
		fmt.Printf("FD ERR:%v\n", fd_err)
		os.Exit(1)
	}
	flock_err := syscall.Flock(fd, syscall.LOCK_EX)
	if flock_err != nil {
		fmt.Printf("LOCK ERR:%v\n", flock_err)
		os.Exit(1)
	}
	// beginning of the code getting the exclusive lock
	fmt.Printf(".")
	time.Sleep(time.Second * 10)
	// end of the code getting the exclusive lock
	funlock_err := syscall.Flock(fd, syscall.LOCK_UN)
	if funlock_err != nil {
		fmt.Printf("UNLOCK ERR:%v\n", funlock_err)
		unlink_err := syscall.Unlink(LOCK_PATH)
		if unlink_err != nil {
			fmt.Printf("UNLINK ERR:%v\n", unlink_err)
		}
		os.Exit(1)
	}
	close_err := syscall.Close(fd)
	if close_err != nil {
		fmt.Printf("CLOSE ERR:%v\n", close_err)
	}
	unlink_err := syscall.Unlink(LOCK_PATH)
	if unlink_err != nil {
		fmt.Printf("UNLINK ERR:%v\n", unlink_err)
	}
}
开发者ID:bradclawsie,项目名称:code,代码行数:33,代码来源:flock.go

示例3: removeUnit

func (m *SystemdManager) removeUnit(name string) {
	log.Infof("Unlinking systemd unit %s from target %s", name, m.Target.Name())
	link := m.getLocalPath(path.Join(m.Target.Name()+".wants", name))
	syscall.Unlink(link)

	file := m.getLocalPath(name)
	log.Infof("Removing systemd unit file %s", file)
	syscall.Unlink(file)
}
开发者ID:jsdir,项目名称:fleet,代码行数:9,代码来源:manager.go

示例4: TestReadOneSessFile

func TestReadOneSessFile(tst *testing.T) {
	fn := "/tmp/abcd.aaa"
	syscall.Unlink(fn)
	s, e := readOneSessFile(fn)
	if s != nil || e == nil {
		tst.Errorf("Should return error, get s=%v, e=%v", s, e)
	}

	e = ioutil.WriteFile(fn, []byte("1234"), 0666)
	if e != nil {
		tst.Errorf("Write file error %v", e)
	}
	s, e = readOneSessFile(fn)
	if s != nil || e == nil {
		tst.Errorf("Should return error, get s=%v, e=%v", s, e)
	}

	syscall.Unlink(fn)
	e = ioutil.WriteFile(fn, []byte("1234\n2015\n11"), 0666)
	if e != nil {
		tst.Errorf("Write file error %v", e)
	}
	s, e = readOneSessFile(fn)
	if e == nil {
		tst.Errorf("Should return error, get s=%v, e=%v", s, e)
	} else {
		tst.Logf("return s=%v, e=%v", s, e)
	}

	// time format ok, but expired
	syscall.Unlink(fn)
	e = ioutil.WriteFile(fn, []byte("1234\n2015-01-02 12:13:14 -0700\n{}"), 0666)
	if e != nil {
		tst.Errorf("Write file error %v", e)
	}
	s, e = readOneSessFile(fn)
	if s != nil || e != nil {
		tst.Errorf("Should return not error, get s=%v, e=%v", s, e)
	} else {
		tst.Logf("return s=%v, e=%v", s, e)
	}

	// every thing ok
	syscall.Unlink(fn)
	e = ioutil.WriteFile(fn, []byte("1234\n2030-01-02 12:13:14 -0700\n{}"), 0666)
	if e != nil {
		tst.Errorf("Write file error %v", e)
	}
	s, e = readOneSessFile(fn)
	if s == nil || e != nil {
		tst.Errorf("Should return not error, get s=%v, e=%v", s, e)
	} else {
		tst.Logf("return s=%v, e=%v", s, e)
	}

}
开发者ID:pastebt,项目名称:sess,代码行数:56,代码来源:sess_test.go

示例5: Close

// close and remove all resources
func (idx *Indexer) Close() {
	syscall.Unlink(idx.docTxtFile.Name())
	idx.docTxtFile.Close()
	syscall.Unlink(idx.wordTxtFile.Name())
	idx.wordTxtFile.Close()
	syscall.Unlink(idx.docCdbFile.Name())
	idx.docCdbFile.Close()
	syscall.Unlink(idx.wordCdbFile.Name())
	idx.wordCdbFile.Close()
	idx.wordMap = nil
}
开发者ID:marble58,项目名称:fulltext,代码行数:12,代码来源:indexer.go

示例6: Unlink

func (constor *Constor) Unlink(header *fuse.InHeader, name string) (code fuse.Status) {
	var stat syscall.Stat_t

	parent := constor.inodemap.findInodePtr(header.NodeId)
	if parent == nil {
		constor.error("parent == nil")
		return fuse.ENOENT
	}
	constor.log("%s %s", parent.id, name)
	id, err := constor.getid(-1, parent.id, name)
	if err != nil {
		constor.error("getid failed %s %s", parent.id, name)
		return fuse.ToStatus(err)
	}
	inode := constor.inodemap.findInodeId(id)
	if inode == nil {
		constor.error("%s %s : inode == nil", parent.id, name)
		return fuse.ENOENT
	}
	if inode.layer == 0 {
		linkcnt, err := constor.declinkscnt(inode.id)
		if err != nil {
			constor.error("declinkscnt %s : %s", inode.id, err)
			return fuse.ToStatus(err)
		}
		if linkcnt == 0 {
			path := constor.getPath(0, inode.id)
			if err := syscall.Unlink(path); err != nil {
				constor.error("Unlink failed for %s : %s", path, err)
				return fuse.ToStatus(err)
			}
			inode.layer = -1
		}
	}
	err = constor.copyup(parent)
	if err != nil {
		constor.error("copyup failed on %s : ", parent.id, err)
		return fuse.ToStatus(err)
	}
	// if there is an entry path, delete it
	entrypath := Path.Join(constor.getPath(0, parent.id), name)
	if err := syscall.Lstat(entrypath, &stat); err == nil {
		if err := syscall.Unlink(entrypath); err != nil {
			constor.error("Unlink failed for %s : %s", entrypath, err)
			return fuse.ToStatus(err)
		}
	}
	// if the file is in a lower layer then create a deleted place holder file
	if _, err := constor.getid(-1, parent.id, name); err == nil {
		constor.setdeleted(entrypath)
	}
	return fuse.OK
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:53,代码来源:main.go

示例7: TestIsEncryptedPEM

func TestIsEncryptedPEM(t *testing.T) {
	pemPKFile := writeFakeFile(pemPrivateKey)
	defer syscall.Unlink(pemPKFile)
	pemPKWPFile := writeFakeFile(pemPrivateKeyWithPass)
	defer syscall.Unlink(pemPKWPFile)
	if ssl.IsEncryptedPEM(pemPKFile) {
		t.Errorf("Incorrectly identified unencrypted PEM as encrypted")
	}
	if !ssl.IsEncryptedPEM(pemPKWPFile) {
		t.Errorf("Incorrectly identified encrypted PEM as unencrypted")
	}
}
开发者ID:BrianIp,项目名称:orchestrator,代码行数:12,代码来源:ssl_test.go

示例8: TestAppendKeyPairWithPassword

func TestAppendKeyPairWithPassword(t *testing.T) {
	c, err := ssl.NewTLSConfig("", false)
	if err != nil {
		t.Fatal(err)
	}
	pemCertFile := writeFakeFile(pemCertificate)
	defer syscall.Unlink(pemCertFile)
	pemPKFile := writeFakeFile(pemPrivateKeyWithPass)
	defer syscall.Unlink(pemPKFile)

	if err := ssl.AppendKeyPairWithPassword(c, pemCertFile, pemPKFile, []byte("testing")); err != nil {
		t.Errorf("Failed to append certificate and key to tls config: %s", err)
	}
}
开发者ID:BrianIp,项目名称:orchestrator,代码行数:14,代码来源:ssl_test.go

示例9: DeleteItem

// DeleteItem removes an existing item from the library.
func (library *Library) DeleteItem(id string, itemType int) error {
	if !library.ItemExists(id, itemType) {
		return os.ErrNotExist
	}

	// Delete sub-collections
	if itemType == LibraryItemCollection {
		for _, child := range library.Collections[id].Children {
			library.DeleteItem(child.ID, LibraryItemCollection)
		}
	}

	// Remove stored JSON
	if err := syscall.Unlink(library.getFilePath(id, itemType)); err != nil {
		return err
	}

	// Delete item from library
	switch itemType {
	case LibraryItemSourceGroup, LibraryItemMetricGroup:
		delete(library.Groups, id)

	case LibraryItemScale:
		delete(library.Scales, id)

	case LibraryItemGraph:
		delete(library.Graphs, id)

	case LibraryItemCollection:
		delete(library.Collections, id)
	}

	return nil
}
开发者ID:krishkm-gm,项目名称:facette,代码行数:35,代码来源:item.go

示例10: TestNewTLSConfig

// TODO: Build a fake CA and make sure it loads up
func TestNewTLSConfig(t *testing.T) {
	fakeCA := writeFakeFile(pemCertificate)
	defer syscall.Unlink(fakeCA)

	conf, err := ssl.NewTLSConfig(fakeCA, true)
	if err != nil {
		t.Errorf("Could not create new TLS config: %s", err)
	}
	if conf.ClientAuth != tls.VerifyClientCertIfGiven {
		t.Errorf("Client certificate verification was not enabled")
	}
	if conf.ClientCAs == nil {
		t.Errorf("ClientCA empty even though cert provided")
	}

	conf, err = ssl.NewTLSConfig("", false)
	if err != nil {
		t.Errorf("Could not create new TLS config: %s", err)
	}
	if conf.ClientAuth == tls.VerifyClientCertIfGiven {
		t.Errorf("Client certificate verification was enabled unexpectedly")
	}
	if conf.ClientCAs != nil {
		t.Errorf("Filling in ClientCA somehow without a cert")
	}
}
开发者ID:BrianIp,项目名称:orchestrator,代码行数:27,代码来源:ssl_test.go

示例11: TestBasicStore

func TestBasicStore(t *testing.T) {
	dbfile, _ := ioutil.TempFile("", "basic-store")
	defer syscall.Unlink(dbfile.Name())
	db, err := sql.Open("sqlite3", dbfile.Name())
	if err != nil {
		log.Fatal(err)
	}
	store, _ := NewDBBackend(db, true)

	ExpectTrue(t, store.FindById(1) == nil, "Expected id:1 not to exist.")

	// Create record 1, set description
	store.EditRecord(1, func(c *Component) bool {
		c.Description = "foo"
		return true
	})

	ExpectTrue(t, store.FindById(1) != nil, "Expected id:1 to exist now.")

	// Edit it, but decide not to proceed
	store.EditRecord(1, func(c *Component) bool {
		ExpectTrue(t, c.Description == "foo", "Initial value set")
		c.Description = "bar"
		return false // don't commit
	})
	ExpectTrue(t, store.FindById(1).Description == "foo", "Unchanged in second tx")

	// Now change it
	store.EditRecord(1, func(c *Component) bool {
		c.Description = "bar"
		return true
	})
	ExpectTrue(t, store.FindById(1).Description == "bar", "Description change")
}
开发者ID:q3k,项目名称:stuff-org,代码行数:34,代码来源:dbbackend_test.go

示例12: 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}
}
开发者ID:kuangchanglang,项目名称:go,代码行数:30,代码来源:file_unix.go

示例13: ListenAndServe

func (srv *Server) ListenAndServe(job *engine.Job) string {
	protoAddrs := job.Args
	chErrors := make(chan error, len(protoAddrs))
	for _, protoAddr := range protoAddrs {
		protoAddrParts := strings.SplitN(protoAddr, "://", 2)
		switch protoAddrParts[0] {
		case "unix":
			if err := syscall.Unlink(protoAddrParts[1]); err != nil && !os.IsNotExist(err) {
				log.Fatal(err)
			}
		case "tcp":
			if !strings.HasPrefix(protoAddrParts[1], "127.0.0.1") {
				log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
			}
		default:
			return "Invalid protocol format."
		}
		go func() {
			// FIXME: merge Server.ListenAndServe with ListenAndServe
			chErrors <- ListenAndServe(protoAddrParts[0], protoAddrParts[1], srv, job.GetenvBool("Logging"))
		}()
	}
	for i := 0; i < len(protoAddrs); i += 1 {
		err := <-chErrors
		if err != nil {
			return err.Error()
		}
	}
	return "0"
}
开发者ID:juniorz,项目名称:docker,代码行数:30,代码来源:server.go

示例14: TestNewConfig

func TestNewConfig(t *testing.T) {
	// create a test dotconfig file
	f, err := ioutil.TempFile("", ".dotconfig")
	if err != nil {
		log.Fatal(err)
	}
	defer syscall.Unlink(f.Name())

	ioutil.WriteFile(
		f.Name(),
		[]byte(payload),
		0644,
	)

	// try to read the file
	c, err := NewConfig(f.Name())
	if err != nil {
		log.Fatal(err)
	}

	// c.DotPath should be the same as payload
	if c.DotPath != "/path/to/dotfiles" {
		t.Error("c.DotPath doesn't match")
	}

	// c.Files should be the same as payload
	if c.Files["test_file_1"] != "path-to-test-file-1" {
		t.Error("c.Files doesn't match")
	}

	// c.Files should be the same as payload
	if c.Files["test_file_2"] != "path-to-test-file-2" {
		t.Error("c.Files doesn't match")
	}
}
开发者ID:erroneousboat,项目名称:dot,代码行数:35,代码来源:config_test.go

示例15: Create

func (constor *Constor) Create(input *fuse.CreateIn, name string, out *fuse.CreateOut) (code fuse.Status) {
	dirpath, err := constor.dentrymap.getPath(input.NodeId)
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	constor.log("%s%s %d %d %d", dirpath, name, input.Mode, input.Uid, input.Gid)
	if err := constor.createPath(dirpath); err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	pathl := Path.Join(constor.layers[0], dirpath, name)
	// remove any deleted place holder entries
	if constor.isdeleted(pathl) {
		syscall.Unlink(pathl)
	}
	fd, err := syscall.Open(pathl, syscall.O_CREAT|syscall.O_RDWR, input.Mode)
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}

	err = syscall.Chown(pathl, int(input.Uid), int(input.Gid))
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	F := new(FD)
	F.fd = fd
	F.layer = 0
	constor.putfd(F)
	out.Fh = uint64(uintptr(unsafe.Pointer(F)))
	constor.log("%d", out.Fh)
	return constor.Lookup((*fuse.InHeader)(unsafe.Pointer(input)), name, &out.EntryOut)
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:35,代码来源:main.go


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