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


Golang os.IsExist函数代码示例

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


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

示例1: main

func main() {
	filecsv := `C:\Users\yejianfeng\Desktop\mxm\skill.csv`
	file, err := os.Open(filecsv)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	reader := csv.NewReader(file)
	roleFolder := `C:\Users\yejianfeng\Desktop\mxm\skill\`
	reader.Read()
	for {
		fields, err := reader.Read()
		if err == io.EOF {
			break
		}

		picurl := fields[15]

		jpg := roleFolder + picurl + ".jpg"
		_, err = os.Open(jpg)
		if err == nil || os.IsExist(err) {
			continue
		}

		png := roleFolder + picurl + ".png"
		_, err = os.Open(png)
		if err == nil || os.IsExist(err) {
			continue
		}

		fmt.Println(fields[0])
	}
}
开发者ID:atree1987,项目名称:MyWorks,代码行数:34,代码来源:checkskill.go

示例2: createParents

func createParents(dir string, verbose bool) bool {
	error := false
	dirs := strings.Split(dir, "/")
	base := ""
	for i := range dirs {
		if dirs[i] == "" {
			base = "/"
			continue
		}
		base = base + dirs[i] + string(os.PathSeparator)
		_, err := os.Stat(base)
		if err == nil || os.IsExist(err) {
			continue
		}
		if verbose {
			fmt.Printf("Creating directory %s\n", base)
		}
		err = os.Mkdir(base, coreutils.Mode)
		if err != nil && !os.IsExist(err) {
			fmt.Fprintf(os.Stderr, "Error while creating directory '%s': %v\n", base, err)
			error = true
		}
	}
	return error
}
开发者ID:uiri,项目名称:coreutils,代码行数:25,代码来源:main.go

示例3: RenderDetail

func RenderDetail(shdarray []*DP, t *template.Template, sh string) error {
	var hisName = time.Now().Format("2006-01-02")
	dshfilename := homeDir + "/changshi/today/detail_" + sh + ".html"
	if _, err := os.Stat(dshfilename); os.IsExist(err) {
		os.Remove(dshfilename)
	}
	dshf, _ := os.Create(dshfilename)
	dshfbw := bufio.NewWriter(dshf)
	err := t.ExecuteTemplate(dshfbw, "detail.tmpl", shdarray)
	if err != nil {
		return err
	}
	dshfbw.Flush()
	dshf.Close()

	dshhfilename := homeDir + "/changshi/his/d_" + sh + "_" + hisName + ".html"
	if _, err := os.Stat(dshhfilename); os.IsExist(err) {
		os.Remove(dshhfilename)
	}
	dshhf, _ := os.Create(dshhfilename)
	dshhfbw := bufio.NewWriter(dshhf)
	err1 := t.ExecuteTemplate(dshhfbw, "detail.tmpl", shdarray)
	if err1 != nil {
		return err
	}
	dshhfbw.Flush()
	dshhf.Close()
	return nil
}
开发者ID:wenxiaoyu,项目名称:traffic,代码行数:29,代码来源:main.go

示例4: copyDir

func copyDir(srcDir, destDir string) (fileCount int, err error) {
	fileCount = 0
	err = os.MkdirAll(destDir, 0777)
	if err != nil && !os.IsExist(err) {
		return fileCount, err
	}
	err = filepath.Walk(srcDir, func(path string, fi os.FileInfo, err error) error {
		fileCount++
		base := strings.Replace(path, srcDir, "", 1)
		dest := filepath.Join(destDir, base)
		if fi.IsDir() {
			err := os.Mkdir(dest, 0777)
			if os.IsExist(err) {
				return nil
			} else {
				return err
			}
		} else {
			log.Printf("path: %s, base: %s", path, base)
			_, err := copyFile(path, dest)
			return err
		}
	})
	return
}
开发者ID:kc87654321,项目名称:goxc,代码行数:25,代码来源:copy-resources.go

示例5: mkdirAll

func (i *inode) mkdirAll(terms []string, perm os.FileMode) error {
	if len(terms) == 0 {
		return nil
	}

	err := i.new(terms[0], Uid, Gid, perm)
	if len(terms) == 1 {
		if os.IsExist(err) {
			return nil
		}
		return err
	}

	dir := i.children[terms[0]]

	switch {

	case err == nil:
		return dir.mkdirAll(terms[1:], perm)

	case os.IsExist(err):
		// If the child is not a directory, fail
		if !i.children[terms[0]].IsDir() {
			return err
		}
		// If it is a directory, just continue
		return dir.mkdirAll(terms[1:], perm)

	default:
		// Some other error
		return err

	}

}
开发者ID:jfindley,项目名称:testfs,代码行数:35,代码来源:dirs.go

示例6: runTaskCopyResources

func runTaskCopyResources(tp TaskParams) error {
	resources := core.ParseIncludeResources(tp.WorkingDirectory, tp.Settings.ResourcesInclude, tp.Settings.ResourcesExclude, tp.Settings.IsVerbose())
	destFolder := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())
	log.Printf("resources: %v", resources)
	for _, resource := range resources {
		if strings.HasPrefix(resource, tp.WorkingDirectory) {
			resource = resource[len(tp.WorkingDirectory)+1:]
		}
		//_, resourcebase := filepath.Split(resource)
		sourcePath := filepath.Join(tp.WorkingDirectory, resource)
		destPath := filepath.Join(destFolder, resource)
		finfo, err := os.Lstat(sourcePath)
		if err != nil {
			return err
		}
		if finfo.IsDir() {
			err = os.MkdirAll(destPath, 0777)
			if err != nil && !os.IsExist(err) {
				return err
			}
		} else {
			err = os.MkdirAll(filepath.Dir(destPath), 0777)
			if err != nil && !os.IsExist(err) {
				return err
			}
			_, err = copyFile(sourcePath, destPath)
		}
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:kc87654321,项目名称:goxc,代码行数:33,代码来源:copy-resources.go

示例7: CreateDatabase

//Called to create the database for the first time
func (sp *FileStorageProvider) CreateDatabase(opts map[string]string) error {
	for i := 0; i < NUMFILES; i++ {
		//Open file
		dbpath, ok := opts["dbpath"]
		if !ok {
			log.Panicf("Expected dbpath")
		}
		fname := fmt.Sprintf("%s/blockstore.%02x.db", dbpath, i)
		//write file descriptor
		{
			f, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
			if err != nil && !os.IsExist(err) {
				log.Panicf("Problem with blockstore DB: ", err)
			} else if os.IsExist(err) {
				return bprovider.ErrExists
			}
			//Add a file tag
			//An exercise left for the reader: if you remove this, everything breaks :-)
			//Hint: what is the physical address of the first byte of file zero?
			_, err = f.Write([]byte("QUASARDB"))
			if err != nil {
				log.Panicf("Could not write to blockstore:", err)
			}

			err = f.Close()
			if err != nil {
				log.Panicf("Error on close %v", err)
			}
		}
	}
	return nil
}
开发者ID:gtfierro,项目名称:btrdb,代码行数:33,代码来源:fileprovider.go

示例8: ServeHTTP

// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
// If so, control is handed over to ServeListing.
func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
	var bc *Config
	// See if there's a browse configuration to match the path
	for i := range b.Configs {
		if httpserver.Path(r.URL.Path).Matches(b.Configs[i].PathScope) {
			bc = &b.Configs[i]
			goto inScope
		}
	}
	return b.Next.ServeHTTP(w, r)
inScope:

	// Browse works on existing directories; delegate everything else
	requestedFilepath, err := bc.Root.Open(r.URL.Path)
	if err != nil {
		switch {
		case os.IsPermission(err):
			return http.StatusForbidden, err
		case os.IsExist(err):
			return http.StatusNotFound, err
		default:
			return b.Next.ServeHTTP(w, r)
		}
	}
	defer requestedFilepath.Close()

	info, err := requestedFilepath.Stat()
	if err != nil {
		switch {
		case os.IsPermission(err):
			return http.StatusForbidden, err
		case os.IsExist(err):
			return http.StatusGone, err
		default:
			return b.Next.ServeHTTP(w, r)
		}
	}
	if !info.IsDir() {
		return b.Next.ServeHTTP(w, r)
	}

	// Do not reply to anything else because it might be nonsensical
	switch r.Method {
	case http.MethodGet, http.MethodHead:
		// proceed, noop
	case "PROPFIND", http.MethodOptions:
		return http.StatusNotImplemented, nil
	default:
		return b.Next.ServeHTTP(w, r)
	}

	// Browsing navigation gets messed up if browsing a directory
	// that doesn't end in "/" (which it should, anyway)
	if !strings.HasSuffix(r.URL.Path, "/") {
		staticfiles.Redirect(w, r, r.URL.Path+"/", http.StatusTemporaryRedirect)
		return 0, nil
	}

	return b.ServeListing(w, r, requestedFilepath, bc)
}
开发者ID:FiloSottile,项目名称:caddy,代码行数:62,代码来源:browse.go

示例9: Mount

// Mount maps an RBD image and mount it on /mnt/ceph/<datastore>/<volume> directory
// FIXME: Figure out how to use rbd locks
func (cv *CephVolume) Mount() error {
	cd := cv.driver
	// Directory to mount the volume
	dataStoreDir := filepath.Join(cd.mountBase, cv.PoolName)
	volumeDir := filepath.Join(dataStoreDir, cv.VolumeName)

	devName, err := cv.mapImage()
	if err != nil {
		return err
	}

	// Create directory to mount
	if err := os.MkdirAll(cd.mountBase, 0700); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", cd.mountBase, err)
	}

	if err := os.MkdirAll(dataStoreDir, 0700); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", dataStoreDir)
	}

	if err := os.MkdirAll(volumeDir, 0777); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", volumeDir)
	}

	// Mount the RBD
	if err := syscall.Mount(devName, volumeDir, "ext4", 0, ""); err != nil && err != syscall.EBUSY {
		return fmt.Errorf("Failed to mount RBD dev %q: %v", devName, err.Error())
	}

	return nil
}
开发者ID:cloudstrack,项目名称:volplugin,代码行数:33,代码来源:volume.go

示例10: Get

func (d *Driver) Get(id, mountLabel string) (string, error) {
	mp := path.Join(d.home, "mnt", id)

	// Create the target directories if they don't exist
	if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {
		return "", err
	}

	// Mount the device
	if err := d.DeviceSet.MountDevice(id, mp, mountLabel); err != nil {
		return "", err
	}

	rootFs := path.Join(mp, "rootfs")
	if err := os.MkdirAll(rootFs, 0755); err != nil && !os.IsExist(err) {
		d.DeviceSet.UnmountDevice(id)
		return "", err
	}

	idFile := path.Join(mp, "id")
	if _, err := os.Stat(idFile); err != nil && os.IsNotExist(err) {
		// Create an "id" file with the container/image id in it to help reconscruct this in case
		// of later problems
		if err := ioutil.WriteFile(idFile, []byte(id), 0600); err != nil {
			d.DeviceSet.UnmountDevice(id)
			return "", err
		}
	}

	return rootFs, nil
}
开发者ID:technosophos,项目名称:flynn,代码行数:31,代码来源:driver.go

示例11: Save

func (i *indexMeta) Save(path string) (err error) {
	indexMetaPath := indexMetaPath(path)
	// ensure any necessary parent directories exist
	err = os.MkdirAll(path, 0700)
	if err != nil {
		if os.IsExist(err) {
			return ErrorIndexPathExists
		}
		return err
	}
	metaBytes, err := json.Marshal(i)
	if err != nil {
		return err
	}
	indexMetaFile, err := os.OpenFile(indexMetaPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
	if err != nil {
		if os.IsExist(err) {
			return ErrorIndexPathExists
		}
		return err
	}
	defer func() {
		if ierr := indexMetaFile.Close(); err == nil && ierr != nil {
			err = ierr
		}
	}()
	_, err = indexMetaFile.Write(metaBytes)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:bcampbell,项目名称:bleve,代码行数:32,代码来源:index_meta.go

示例12: createDeviceNode

// Creates the device node in the rootfs of the container.
func createDeviceNode(rootfs string, node *configs.Device) error {
	dest := filepath.Join(rootfs, node.Path)
	if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil {
		return err
	}
	if err := mknodDevice(dest, node); err != nil {
		if os.IsExist(err) {
			return nil
		}
		if err != syscall.EPERM {
			return err
		}
		// containers running in a user namespace are not allowed to mknod
		// devices so we can just bind mount it from the host.
		f, err := os.Create(dest)
		if err != nil && !os.IsExist(err) {
			return err
		}
		if f != nil {
			f.Close()
		}
		return syscall.Mount(node.Path, dest, "bind", syscall.MS_BIND, "")
	}
	return nil
}
开发者ID:jorik041,项目名称:docker,代码行数:26,代码来源:rootfs_linux.go

示例13: MakeLocalCasTable

// MakeLocalCasTable returns a CasTable rooted at rootDir.
func MakeLocalCasTable(rootDir string) (CasTable, error) {
	// Creates 16^3 (4096) directories. Preferable values are 2 or 3.
	prefixLength := 3
	// Currently hardcoded for SHA-1 but could be used for any length.
	hashLength := sha1.Size * 2

	if !filepath.IsAbs(rootDir) {
		return nil, fmt.Errorf("MakeCasTable(%s) is not valid", rootDir)
	}
	rootDir = filepath.Clean(rootDir)
	casDir := filepath.Join(rootDir, casName)
	if err := os.MkdirAll(casDir, 0750); err != nil && !os.IsExist(err) {
		return nil, fmt.Errorf("MakeCasTable(%s): failed to create the directory: %s", casDir, err)
	} else if !os.IsExist(err) {
		// Create all the prefixes at initialization time so they don't need to be
		// tested all the time.
		for i := 0; i < prefixSpace(uint(prefixLength)); i++ {
			prefix := fmt.Sprintf("%0*x", prefixLength, i)
			if err := os.Mkdir(filepath.Join(casDir, prefix), 0750); err != nil && !os.IsExist(err) {
				return nil, fmt.Errorf("Failed to create %s: %s\n", prefix, err)
			}
		}
	}
	return &casTable{
		rootDir,
		casDir,
		prefixLength,
		hashLength,
		regexp.MustCompile(fmt.Sprintf("^([a-f0-9]{%d})$", hashLength)),
		makeTrash(casDir),
	}, nil
}
开发者ID:maruel,项目名称:dumbcas,代码行数:33,代码来源:cas_local.go

示例14: Init

func (b *basedir) Init(path string) error {
	var err error
	b.path, err = filepath.Abs(path)
	if err != nil {
		return err
	}

	if err := MakeDir(b.path); err != nil && !os.IsExist(err) {
		return err
	}

	b.configDir = filepath.Join(b.path, CONFIG_DIR)
	if err := MakeDir(b.configDir); err != nil && !os.IsExist(err) {
		return err
	}
	if err := os.Chmod(b.configDir, 0700); err != nil {
		return err
	}

	b.dataDir = filepath.Join(b.path, DATA_DIR)
	if err := MakeDir(b.dataDir); err != nil && !os.IsExist(err) {
		return err
	}

	b.binDir = filepath.Join(b.path, BIN_DIR)
	if err := MakeDir(b.binDir); err != nil && !os.IsExist(err) {
		return err
	}

	return nil
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:31,代码来源:basedir.go

示例15: Mount

// Mount records mounted volume
func (d *Driver) Mount(do storage.DriverOptions) (*storage.Mount, error) {
	d.logStat(getFunctionName())
	if err := os.MkdirAll(d.BaseMountPath, 0700); err != nil && !os.IsExist(err) {
		return nil, errored.Errorf("error creating %q directory: %v", d.BaseMountPath, err)
	}

	volumePath := filepath.Join(d.BaseMountPath, do.Volume.Params["pool"], do.Volume.Name)
	if err := os.MkdirAll(volumePath, 0700); err != nil && !os.IsExist(err) {
		return nil, errored.Errorf("error creating %q directory: %v", volumePath, err)
	}

	mount := &storage.Mount{
		Path:   volumePath,
		Volume: do.Volume,
	}

	content, err := json.Marshal(mount)
	if err != nil {
		return nil, err
	}

	_, err = d.client.Set(context.Background(), path.Join(mountedPrefix, do.Volume.Name), string(content), &client.SetOptions{PrevExist: client.PrevNoExist})
	logrus.Infof("%v %v", path.Join(mountedPrefix, do.Volume.Name), err)
	if err != nil {
		return nil, err
	}

	return mount, nil
}
开发者ID:contiv,项目名称:volplugin,代码行数:30,代码来源:test.go


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