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


Golang os.Remove函数代码示例

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


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

示例1: RemoveSnapServices

// RemoveSnapServices disables and removes service units for the applications from the snap which are services.
func RemoveSnapServices(s *snap.Info, inter interacter) error {
	sysd := systemd.New(dirs.GlobalRootDir, inter)

	nservices := 0

	for _, app := range s.Apps {
		if app.Daemon == "" {
			continue
		}
		nservices++

		serviceName := filepath.Base(app.ServiceFile())
		if err := sysd.Disable(serviceName); err != nil {
			return err
		}

		if err := os.Remove(app.ServiceFile()); err != nil && !os.IsNotExist(err) {
			logger.Noticef("Failed to remove service file for %q: %v", serviceName, err)
		}

		if err := os.Remove(app.ServiceSocketFile()); err != nil && !os.IsNotExist(err) {
			logger.Noticef("Failed to remove socket file for %q: %v", serviceName, err)
		}
	}

	// only reload if we actually had services
	if nservices > 0 {
		if err := sysd.DaemonReload(); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:clobrano,项目名称:snappy,代码行数:35,代码来源:services.go

示例2: Run

func (this *MemeOCR) Run(image string) (*OCRResult, error) {
	imageTif := fmt.Sprintf("%s_meme.jpg", image)
	outText := fmt.Sprintf("%s_meme", image)
	preprocessingArgs := []string{image, "-resize", "400%", "-fill", "black", "-fuzz", "10%", "+opaque", "#FFFFFF", imageTif}
	tesseractArgs := []string{"-l", "meme", imageTif, outText}

	err := runProcessorCommand(GetExecPath(), preprocessingArgs)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Meme preprocessing command failed with error = %v", err))
	}
	defer os.Remove(imageTif)

	err = runProcessorCommand("tesseract", tesseractArgs)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Meme tesseract command failed with error = %v", err))
	}
	defer os.Remove(outText + ".txt")

	text, err := ioutil.ReadFile(outText + ".txt")
	if err != nil {
		return nil, err
	}

	result := strings.ToLower(strings.TrimSpace(string(text[:])))

	return newOCRResult(this.name, result), nil
}
开发者ID:rizzles,项目名称:convert,代码行数:27,代码来源:ocrcommands.go

示例3: UnixAudienceListener

func UnixAudienceListener(sockaddr string) {
	fi, err := os.Stat(sockaddr)
	if err == nil {
		fmode := fi.Mode()
		if fmode&os.ModeType == os.ModeSocket {
			o.Warn("Removing stale socket at %s", sockaddr)
			os.Remove(sockaddr)
		} else {
			o.Fail("%s exists and is not a socket", sockaddr)
		}
	}
	laddr, err := net.ResolveUnixAddr("unix", sockaddr)
	o.MightFail(err, "Couldn't resolve audience socket address")
	l, err := net.ListenUnix("unix", laddr)
	o.MightFail(err, "Couldn't start audience unixsock listener")
	// Fudge the permissions on the unixsock!
	fi, err = os.Stat(sockaddr)
	if err == nil {
		os.Chmod(sockaddr, fi.Mode()|0777)
	} else {
		o.Warn("Couldn't fudge permission on audience socket: %s", err)
	}

	// make sure we clean up the unix socket when we die.
	defer l.Close()
	defer os.Remove(sockaddr)
	AudienceListener(l)
}
开发者ID:kuroneko,项目名称:Orchestra,代码行数:28,代码来源:audience.go

示例4: makeDiskImage

func makeDiskImage() error {
	log.Printf("Creating %s MB hard disk image...", B2D.DISKSIZE)
	vbm("createhd", "--format", "VMDK", "--filename", B2D.DISK, "--size", B2D.DISKSIZE)

	// We do the following so boot2docker vm will auto-format the disk for us
	// upon first boot.
	const tmp_flag_file = "format-flag.txt"
	const tmp_vmdk_file = "format-flag.vmdk"
	f, err := os.Create(tmp_flag_file)
	if err != nil {
		return err
	}
	err = f.Truncate(5 * 1024 * 1024) // 5MB
	if err != nil {
		return err
	}
	_, err = f.WriteString("boot2docker, please format-me\n")
	if err != nil {
		return err
	}
	err = f.Close()
	if err != nil {
		return err
	}

	vbm("convertfromraw", tmp_flag_file, tmp_vmdk_file, "--format", "VMDK")
	vbm("clonehd", tmp_vmdk_file, B2D.DISK, "--existing")
	vbm("closemedium", "disk", tmp_vmdk_file)
	os.Remove(tmp_flag_file)
	os.Remove(tmp_vmdk_file)
	return nil
}
开发者ID:jamtur01,项目名称:boot2docker,代码行数:32,代码来源:boot2docker.go

示例5: TestReadSymlinkedDirectoryToFile

// Reading a symlink to a file must fail
func TestReadSymlinkedDirectoryToFile(t *testing.T) {
	var err error
	var file *os.File

	if file, err = os.Create("/tmp/testReadSymlinkToFile"); err != nil {
		t.Fatalf("failed to create file: %s", err)
	}

	file.Close()

	if err = os.Symlink("/tmp/testReadSymlinkToFile", "/tmp/fileLinkTest"); err != nil {
		t.Errorf("failed to create symlink: %s", err)
	}

	var path string
	if path, err = ReadSymlinkedDirectory("/tmp/fileLinkTest"); err == nil {
		t.Fatalf("ReadSymlinkedDirectory on a symlink to a file should've failed")
	}

	if path != "" {
		t.Fatalf("path should've been empty: %s", path)
	}

	if err = os.Remove("/tmp/testReadSymlinkToFile"); err != nil {
		t.Errorf("failed to remove file: %s", err)
	}

	if err = os.Remove("/tmp/fileLinkTest"); err != nil {
		t.Errorf("failed to remove symlink: %s", err)
	}
}
开发者ID:idvoretskyi,项目名称:coreos-kubernetes,代码行数:32,代码来源:utils_test.go

示例6: TestInsertRead

func TestInsertRead(t *testing.T) {
	tmp := "/tmp/tiedot_test_col"
	os.Remove(tmp)
	defer os.Remove(tmp)
	col, err := OpenCollection(tmp)
	if err != nil {
		t.Fatalf("Failed to open: %v", err)
		return
	}
	defer col.Close()
	docs := [][]byte{
		[]byte("abc"),
		[]byte("1234")}
	ids := [2]int{}
	if ids[0], err = col.Insert(docs[0]); ids[0] != 0 || err != nil {
		t.Fatalf("Failed to insert: %d %v", ids[0], err)
	}
	if ids[1], err = col.Insert(docs[1]); err != nil {
		t.Fatalf("Failed to insert: %v", err)
	}
	if doc0 := col.Read(ids[0]); doc0 == nil || strings.TrimSpace(string(doc0)) != string(docs[0]) {
		t.Fatal("Failed to read", doc0)
	}
	if doc1 := col.Read(ids[1]); doc1 == nil || strings.TrimSpace(string(doc1)) != string(docs[1]) {
		t.Fatalf("Failed to read")
	}
	// it shall not panic
	col.Read(col.Size)
}
开发者ID:huanshi,项目名称:tiedot,代码行数:29,代码来源:collection_test.go

示例7: run

func (m *migrateCmd) run(e *parsecli.Env) error {
	c, err := parsecli.ConfigFromDir(e.Root)
	if err != nil {
		return err
	}

	c, err = m.upgradeLegacy(e, c)
	if err != nil {
		return err
	}
	localErr := parsecli.StoreConfig(e, c)
	projectErr := parsecli.StoreProjectConfig(e, c)
	if localErr == nil && projectErr == nil {
		legacy := filepath.Join(e.Root, parsecli.LegacyConfigFile)
		err := os.Remove(legacy)
		if err != nil {
			fmt.Fprintf(e.Err, "Could not delete: %q. Please remove this file manually.\n", legacy)
		}
	} else {
		local := filepath.Join(e.Root, parsecli.ParseLocal)
		err := os.Remove(local)
		if err != nil {
			fmt.Fprintf(e.Err, "Failed to clean up: %q. Please remove this file manually.\n", local)
		}
		project := filepath.Join(e.Root, parsecli.ParseProject)
		err = os.Remove(project)
		if err != nil {
			fmt.Fprintf(e.Err, "Failed to clean up: %q. Please remove this file manually.\n", project)
		}
	}
	fmt.Fprintln(e.Out, "Successfully migrated to the preferred config format.")
	return nil
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:33,代码来源:migrate.go

示例8: TestVerify

func TestVerify(t *testing.T) {
	o := &Options{noClone: true}
	db, err := CreateTemp("", "temp", ".db", o)
	if err != nil {
		t.Fatal(err)
	}

	defer func() {
		name := db.Name()
		err := db.Close()
		if err := os.Remove(name); err != nil {
			t.Error(err)
		}
		if err := os.Remove(o._WAL); err != nil {
			t.Error(err)
		}
		if err != nil {
			t.Error(err)
		}
	}()

	t.Log(db.Name(), o._WAL)
	if err := db.Verify(nil, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:rn2dy,项目名称:camlistore,代码行数:26,代码来源:all_test.go

示例9: TestCreate

func TestCreate(t *testing.T) {
	const name = "_testdata/tempname"
	os.Remove(name)
	o := &Options{noClone: true}
	db, err := Create(name, o)
	if err != nil {
		t.Fatal(err)
	}

	defer func() {
		err := db.Close()
		if err := os.Remove(name); err != nil {
			t.Error(err)
		}
		if err := os.Remove(o._WAL); err != nil {
			t.Error(err)
		}
		if err != nil {
			t.Error(err)
		}
	}()

	if _, err = Create(name, &Options{noClone: true}); err == nil {
		t.Error("unexpected success")
		return
	}

	if _, err = Open(name, &Options{noClone: true}); err == nil {
		t.Error("unexpected success")
		return
	}
}
开发者ID:rn2dy,项目名称:camlistore,代码行数:32,代码来源:all_test.go

示例10: Put

func (f *fileStorageWriter) Put(name string, r io.Reader, length int64) error {
	if isInternalPath(name) {
		return &os.PathError{
			Op:   "Put",
			Path: name,
			Err:  os.ErrPermission,
		}
	}
	fullpath := f.fullPath(name)
	dir := filepath.Dir(fullpath)
	if err := os.MkdirAll(dir, 0755); err != nil {
		return err
	}
	tmpdir := filepath.Join(f.path, ".tmp")
	if err := os.MkdirAll(tmpdir, 0755); err != nil {
		return err
	}
	defer os.Remove(tmpdir)
	// Write to a temporary file first, and then move (atomically).
	file, err := ioutil.TempFile(tmpdir, "juju-filestorage-")
	if err != nil {
		return err
	}
	_, err = io.CopyN(file, r, length)
	file.Close()
	if err != nil {
		os.Remove(file.Name())
		return err
	}
	return utils.ReplaceFile(file.Name(), fullpath)
}
开发者ID:jameinel,项目名称:core,代码行数:31,代码来源:filestorage.go

示例11: TestWALName

func TestWALName(t *testing.T) {
	db, err := CreateTemp("", "kv-wal-name", ".test", &Options{noClone: true})
	if err != nil {
		t.Fatal(err)
	}

	defer func(n, wn string) {
		if _, err := os.Stat(n); err != nil {
			t.Error(err)
		} else {
			if err := os.Remove(n); err != nil {
				t.Error(err)
			}
		}
		if _, err := os.Stat(wn); err != nil {
			t.Error(err)
		} else {
			if err := os.Remove(wn); err != nil {
				t.Error(err)
			}
		}
		t.Logf("%q\n%q", n, wn)

	}(db.Name(), db.WALName())

	if err := db.Close(); err != nil {
		t.Error(err)
		return
	}

	if n := db.WALName(); n != "" {
		t.Error(n)
	}
}
开发者ID:rn2dy,项目名称:camlistore,代码行数:34,代码来源:all_test.go

示例12: Display

func (eogHandler) Display(ctx *context.T, mimetype string, r io.ReadCloser) (func(), error) {
	// eog cannot read from a pipe, so we have to write the file to
	// the filesystem before displaying it.
	defer r.Close()
	tmp, err := ioutil.TempFile("", "")
	if err != nil {
		return nil, err
	}
	if _, err := io.Copy(tmp, r); err != nil {
		os.Remove(tmp.Name())
		return nil, err
	}
	tmp.Close()

	cmd := exec.Command("eog", "--display", ":0", "-f", tmp.Name())
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	stop := func() {
		if err := cmd.Process.Kill(); err != nil {
			vlog.Errorf("Could not kill eog: %v", err)
		}
		cmd.Wait()
		os.Remove(tmp.Name())
	}
	if err := cmd.Start(); err != nil {
		return stop, err
	}
	return stop, nil
}
开发者ID:vanadium,项目名称:media-sharing,代码行数:29,代码来源:mediaserver.go

示例13: TestSystem

func TestSystem(t *testing.T) {
	tmpdir, err := ioutil.TempDir("", "")
	require.NoError(t, err)
	defer os.RemoveAll(tmpdir)

	sys := NewSystem(SystemConfig{BuildTempDir: tmpdir})
	{
		tmpFile1, err := sys.SmallTempFile()
		if assert.NoError(t, err) {
			defer os.Remove(tmpFile1.Name())
			defer tmpFile1.Close()
			tmpFile2, err := sys.SmallTempFile()
			if assert.NoError(t, err) {
				defer os.Remove(tmpFile2.Name())
				defer tmpFile2.Close()
				assert.NotEqual(t, tmpFile1.Name(), tmpFile2.Name())
			}
		}
	}
	{
		tmpDir1, err := sys.TempDirForBuild()
		if assert.NoError(t, err) {
			assert.True(t, strings.HasPrefix(tmpDir1, tmpdir))
			tmpDir2, err := sys.TempDirForBuild()
			if assert.NoError(t, err) {
				assert.True(t, strings.HasPrefix(tmpDir2, tmpdir))
				assert.NotEqual(t, tmpDir1, tmpDir2)
			}
		}
	}
}
开发者ID:bunsanorg,项目名称:pm,代码行数:31,代码来源:system_test.go

示例14: TestCanonicalCircular

func TestCanonicalCircular(t *testing.T) {
	tmp1, err := tmpfile("circular")
	if err != nil {
		t.Fatal(err)
	}
	tmp2, err := tmpfile("circular")
	if err != nil {
		t.Fatal(nonil(err, os.Remove(tmp1)))
	}
	defer removeall(tmp1, tmp2)
	// Symlink tmp1 -> tmp2.
	if err = nonil(os.Remove(tmp1), os.Symlink(tmp2, tmp1)); err != nil {
		t.Fatal(err)
	}
	// Symlnik tmp2 -> tmp1.
	if err = nonil(os.Remove(tmp2), os.Symlink(tmp1, tmp2)); err != nil {
		t.Fatal(err)
	}
	if _, err = canonical(tmp1); err == nil {
		t.Fatalf("want canonical(%q)!=nil", tmp1)
	}
	if _, ok := err.(*os.PathError); !ok {
		t.Fatalf("want canonical(%q)=os.PathError; got %T", tmp1, err)
	}
}
开发者ID:kaocs,项目名称:notify,代码行数:25,代码来源:util_unix_test.go

示例15: BenchmarkFirst16

func BenchmarkFirst16(b *testing.B) {
	const n = 5000
	g := runtime.GOMAXPROCS(0)
	defer runtime.GOMAXPROCS(g)
	o := &Options{noClone: true}
	db, err := CreateTemp("_testdata", "temp", ".db", o)
	if err != nil {
		b.Fatal(err)
	}

	dbname := db.Name()
	defer func(n string) {
		db.Close()
		os.Remove(n)
		os.Remove(o._WAL)
	}(dbname)

	rng := fc()
	for i := 0; i < n; i++ {
		if err := db.Set(n2b(rng.Next()), n2b(rng.Next())); err != nil {
			b.Fatal(err)
		}
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		db.First()
	}
	b.StopTimer()
}
开发者ID:rn2dy,项目名称:camlistore,代码行数:29,代码来源:all_test.go


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