本文整理汇总了Golang中os.IsNotExist函数的典型用法代码示例。如果您正苦于以下问题:Golang IsNotExist函数的具体用法?Golang IsNotExist怎么用?Golang IsNotExist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsNotExist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: backupFiles
func backupFiles(versionID string, wg *sync.WaitGroup) {
defer wg.Done()
if _, err := os.Stat(backupDir); err != nil {
if os.IsNotExist(err) {
makeBackupDir()
}
}
if debug {
fmt.Printf("backupFiles - %s\n", versionID)
}
log.Printf("backupFiles - %s\n", versionID)
fileName := fmt.Sprintf("%s%s%s_backup", backupDir, string(os.PathSeparator), versionID)
worldDir := fmt.Sprintf("%s", worldDir)
if _, err := os.Stat(backupDir); err != nil {
if os.IsNotExist(err) {
if debug {
fmt.Println("Nothing to backup right now.")
}
log.Println("Nothing to backup right now.")
} else {
zip := new(archivex.ZipFile)
zip.Create(fileName)
fmt.Printf("worldDir - %s\n", worldDir)
fmt.Printf("fileName - %s\n", fileName)
zip.AddAll(worldDir, true)
fmt.Printf("after addall\n")
zip.Close()
}
}
}
示例2: 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
}
示例3: main
func main() {
flag.StringVar(&repoPrefix, "prefix", "", "The repo name prefix required in order to build.")
flag.Parse()
if repoPrefix == "" {
log.Fatal("Specify a prefix to look for in the repo names with -prefix='name'")
}
if f, err := os.Stat(sourceBase); f == nil || os.IsNotExist(err) {
log.Fatalf("The -src folder, %s, doesn't exist.", sourceBase)
}
if f, err := os.Stat(destBase); f == nil || os.IsNotExist(err) {
log.Fatalf("The -dest folder, %s, doesn't exist.", destBase)
}
if dbConnString != "" {
InitDatabase()
}
goji.Get("/", buildsIndexHandler)
goji.Get("/:name/:repo_tag", buildsShowHandler)
goji.Post("/_github", postReceiveHook)
goji.Serve()
}
示例4: Start
func (d *Driver) Start() error {
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
// Do not execute the rest of boot2docker specific configuration, exit here
if d.ConfigDriveURL != "" {
log.Debugf("Leaving start sequence early, configdrive found")
return nil
}
log.Debugf("Mounting Shared Folders...")
var shareName, shareDir string // TODO configurable at some point
switch runtime.GOOS {
case "darwin":
shareName = "Users"
shareDir = "/Users"
// TODO "linux" and "windows"
}
if shareDir != "" {
if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) {
return err
} else if !os.IsNotExist(err) {
// create mountpoint and mount shared folder
command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs .host:/" + shareName + " " + shareDir
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command)
}
}
return nil
}
示例5: certKeyXor
func certKeyXor(certFile, keyFile string) (bool, []error) {
certInfo, err := os.Stat(certFile)
certExists := !os.IsNotExist(err)
certIsFile := certExists && certInfo.Mode().IsRegular()
keyInfo, err := os.Stat(keyFile)
keyExists := !os.IsNotExist(err)
keyIsFile := keyExists && keyInfo.Mode().IsRegular()
errors := make([]error, 0)
if certExists && certIsFile && keyExists && keyIsFile {
return true, errors
}
if !certExists && !keyExists {
return false, errors
}
if !certExists {
errors = append(errors, fmt.Errorf("Cert %s does not exist", certFile))
} else if !certIsFile {
errors = append(errors, fmt.Errorf("Cert %s is not a file", certFile))
}
if !keyExists {
errors = append(errors, fmt.Errorf("Key %s does not exist", keyFile))
} else if !keyIsFile {
errors = append(errors, fmt.Errorf("Key %s is not a file", keyFile))
}
return false, errors
}
示例6: setupIDs
func (s *Server) setupIDs() error {
clusterIDPath := filepath.Join(s.dataDir, clusterIDFilename)
clusterID, err := s.readID(clusterIDPath)
if err != nil && !os.IsNotExist(err) {
return err
}
if clusterID == "" {
clusterID = uuid.NewV4().String()
s.writeID(clusterIDPath, clusterID)
}
s.ClusterID = clusterID
serverIDPath := filepath.Join(s.dataDir, serverIDFilename)
serverID, err := s.readID(serverIDPath)
if err != nil && !os.IsNotExist(err) {
return err
}
if serverID == "" {
serverID = uuid.NewV4().String()
s.writeID(serverIDPath, serverID)
}
s.ServerID = serverID
return nil
}
示例7: TestTempDirCreate
func TestTempDirCreate(t *testing.T) {
if err := InitDir(); err != nil {
t.Fatalf("Error during creating the temp directory: %s\n", err.Error())
}
if _, err := os.Stat(aufsTempDir); err != nil {
if os.IsNotExist(err) {
t.Fatalf("Temp dir create failed")
} else {
t.Fatalf("Temp dir create failed, %s", err.Error())
}
}
if err := InitFile(); err != nil {
t.Fatalf("Error during creating the test file: %s\n", err.Error())
}
if _, err := os.Stat(testFile3); err != nil {
if os.IsNotExist(err) {
t.Fatalf("Temp dir create failed")
} else {
t.Fatalf("Temp dir create failed, %s", err.Error())
}
}
if err := Cleanup(); err != nil {
t.Fatalf("Error during removing files and dirs: %s\n", err.Error())
}
}
示例8: TestSetUpAndTearDown
func TestSetUpAndTearDown(t *testing.T) {
tempDir, err := ioutil.TempDir("", "CreateVolumes")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
defer os.RemoveAll(tempDir)
fakeID := "my-id"
type VolumeTester interface {
Builder
Cleaner
}
volumes := []VolumeTester{
&EmptyDir{"empty", fakeID, tempDir},
&GCEPersistentDisk{"pd", fakeID, tempDir, "pd-disk", "ext4", "", false, &MockDiskUtil{}, &MockMounter{}},
}
for _, vol := range volumes {
err = vol.SetUp()
path := vol.GetPath()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if _, err := os.Stat(path); os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %v", path)
}
err = vol.TearDown()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if _, err := os.Stat(path); !os.IsNotExist(err) {
t.Errorf("TearDown() failed, original volume path not properly removed: %v", path)
}
}
}
示例9: TestIndexOpen
func TestIndexOpen(t *testing.T) {
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
path := repo.Workdir() + "/heyindex"
_, err := os.Stat(path)
if !os.IsNotExist(err) {
t.Fatal("new index file already exists")
}
idx, err := OpenIndex(path)
checkFatal(t, err)
if path != idx.Path() {
t.Fatalf("mismatched index paths, expected %v, got %v", path, idx.Path())
}
err = idx.Write()
checkFatal(t, err)
_, err = os.Stat(path)
if os.IsNotExist(err) {
t.Fatal("new index file did not get written")
}
}
示例10: TestAllocDir_BuildAlloc
// Test that given a set of tasks, each task gets a directory and that directory
// has the shared alloc dir inside of it.
func TestAllocDir_BuildAlloc(t *testing.T) {
tmp, err := ioutil.TempDir("", "AllocDir")
if err != nil {
t.Fatalf("Couldn't create temp dir: %v", err)
}
defer os.RemoveAll(tmp)
d := NewAllocDir(tmp)
defer d.Destroy()
tasks := []*structs.Task{t1, t2}
if err := d.Build(tasks); err != nil {
t.Fatalf("Build(%v) failed: %v", tasks, err)
}
// Check that the AllocDir and each of the task directories exist.
if _, err := os.Stat(d.AllocDir); os.IsNotExist(err) {
t.Fatalf("Build(%v) didn't create AllocDir %v", tasks, d.AllocDir)
}
for _, task := range tasks {
tDir, ok := d.TaskDirs[task.Name]
if !ok {
t.Fatalf("Task directory not found for %v", task.Name)
}
if _, err := os.Stat(tDir); os.IsNotExist(err) {
t.Fatalf("Build(%v) didn't create TaskDir %v", tasks, tDir)
}
}
}
示例11: loadSpecConfig
func loadSpecConfig() (spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, err error) {
cPath := "config.json"
cf, err := os.Open(cPath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("config.json not found")
}
}
defer cf.Close()
rPath := "runtime.json"
rf, err := os.Open(rPath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("runtime.json not found")
}
}
defer rf.Close()
if err = json.NewDecoder(cf).Decode(&spec); err != nil {
return
}
if err = json.NewDecoder(rf).Decode(&rspec); err != nil {
return
}
return spec, rspec, nil
}
示例12: get
func get(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
log.Println("Serving ", r.URL.String())
repo := p.ByName("repo")
repoStat, err := os.Stat(repo)
if os.IsNotExist(err) || !repoStat.IsDir() {
http.Error(w, "Repo not found", 404)
return
}
arch := p.ByName("arch")
archStat, err := os.Stat(path.Join(repo, "os", arch))
if os.IsNotExist(err) || !archStat.IsDir() {
http.Error(w, "Arch not found", 404)
return
}
name := p.ByName("name")
finalPath := path.Join(repo, "os", arch, name)
nameExt := path.Ext(name)
if nameExt == ".xz" {
getXz(w, finalPath)
} else if nameExt == ".db" {
if fmt.Sprint(repo, ".db") == name {
getDb(w, finalPath)
} else {
http.Error(w, "Database not available", 404)
}
} else {
http.Error(w, "Name not found", 404)
}
}
示例13: doTestPluginMountUnmount
func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec, tmpDir string) {
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
if err != nil {
t.Fatalf("error creating temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
plugMgr := volume.VolumePluginMgr{}
installPluginUnderTest(t, "kubernetes.io", "fakeMounter", tmpDir, execScriptTempl2, nil)
plugMgr.InitPlugins(ProbeVolumePlugins(tmpDir), volume.NewFakeVolumeHost(tmpDir, nil, nil))
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeMounter")
if err != nil {
t.Errorf("Can't find the plugin by name")
}
fake := &mount.FakeMounter{}
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
builder, err := plugin.(*flexVolumePlugin).newBuilderInternal(spec, pod, &flexVolumeUtil{}, fake, exec.New(), "")
volumePath := builder.GetPath()
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
path := builder.GetPath()
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~fakeMounter/vol1", tmpDir)
if path != expectedPath {
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
}
if err := builder.SetUp(nil); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err != nil {
if os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %s", volumePath)
} else {
t.Errorf("SetUp() failed: %v", err)
}
}
t.Logf("Setup successful")
if builder.(*flexVolumeBuilder).readOnly {
t.Errorf("The volume source should not be read-only and it is.")
}
cleaner, err := plugin.(*flexVolumePlugin).newCleanerInternal("vol1", types.UID("poduid"), &flexVolumeUtil{}, fake, exec.New())
if err != nil {
t.Errorf("Failed to make a new Cleaner: %v", err)
}
if cleaner == nil {
t.Errorf("Got a nil Cleaner")
}
if err := cleaner.TearDown(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err == nil {
t.Errorf("TearDown() failed, volume path still exists: %s", volumePath)
} else if !os.IsNotExist(err) {
t.Errorf("SetUp() failed: %v", err)
}
}
示例14: TestUninstall
func TestUninstall(t *testing.T) {
fakeSB := runit.FakeServiceBuilder()
defer fakeSB.Cleanup()
serviceBuilder := &fakeSB.ServiceBuilder
testPodDir, err := ioutil.TempDir("", "testPodDir")
Assert(t).IsNil(err, "Got an unexpected error creating a temp directory")
pod := Pod{
Id: "testPod",
path: testPodDir,
ServiceBuilder: serviceBuilder,
}
manifest := getTestPodManifest(t)
manifestContent, err := manifest.Marshal()
Assert(t).IsNil(err, "couldn't get manifest bytes")
err = ioutil.WriteFile(pod.currentPodManifestPath(), manifestContent, 0744)
Assert(t).IsNil(err, "should have written current manifest")
serviceBuilderFilePath := filepath.Join(serviceBuilder.ConfigRoot, "testPod.yaml")
err = ioutil.WriteFile(serviceBuilderFilePath, []byte("stuff"), 0744)
Assert(t).IsNil(err, "Error writing fake servicebuilder file")
err = pod.Uninstall()
Assert(t).IsNil(err, "Error uninstalling pod")
_, err = os.Stat(serviceBuilderFilePath)
Assert(t).IsTrue(os.IsNotExist(err), "Expected file to not exist after uninstall")
_, err = os.Stat(pod.currentPodManifestPath())
Assert(t).IsTrue(os.IsNotExist(err), "Expected file to not exist after uninstall")
}
示例15: loadSpec
// loadSpec loads the specification from the provided path.
// If the path is empty then the default path will be "config.json"
func (r *libcontainerRuntime) loadSpec(cPath, rPath string) (spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, err error) {
cf, err := os.Open(cPath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("JSON specification file at %s not found", cPath)
}
return spec, rspec, err
}
defer cf.Close()
rf, err := os.Open(rPath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("JSON runtime config file at %s not found", rPath)
}
return spec, rspec, err
}
defer rf.Close()
if err = json.NewDecoder(cf).Decode(&spec); err != nil {
return spec, rspec, fmt.Errorf("unmarshal %s: %v", cPath, err)
}
if err = json.NewDecoder(rf).Decode(&rspec); err != nil {
return spec, rspec, fmt.Errorf("unmarshal %s: %v", rPath, err)
}
return spec, rspec, r.checkSpecVersion(spec)
}