Example #1
0
// walk recursively descends path, calling w.
func walk(path string, info *os.FileInfo, walkFn WalkFunc) os.Error {
	err := walkFn(path, info, nil)
	if err != nil {
		if info.IsDirectory() && err == SkipDir {
			return nil
		}
		return err
	}

	if !info.IsDirectory() {
		return nil
	}

	list, err := readDir(path)
	if err != nil {
		return walkFn(path, info, err)
	}

	for _, fileInfo := range list {
		if err = walk(Join(path, fileInfo.Name), fileInfo, walkFn); err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
func (me *AutoUnionFs) visit(path string, fi *os.FileInfo, err error) error {
	if fi.IsDirectory() {
		roots := me.getRoots(path)
		if roots != nil {
			me.addAutomaticFs(roots)
		}
	}
	return nil
}
Example #3
0
func directoryExists(path string) bool {
	var f *os.FileInfo
	var err os.Error

	if f, err = os.Stat(path); err != nil {
		return false
	}

	return f.IsDirectory()
}
Example #4
0
func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
	out = &EntryOut{}
	splitNs(me.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec)
	splitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
	CopyFileInfo(fi, &out.Attr)
	me.setOwner(&out.Attr)
	if !fi.IsDirectory() && fi.Nlink == 0 {
		out.Nlink = 1
	}
	return out
}
Example #5
0
func (sc *SpecCollector) Walk(path string, f *os.FileInfo, err error) error {
	if err != nil {
		return err
	}
	if f.IsDirectory() {
		return nil
	}
	if strings.HasSuffix(f.Name, SpecSuffix) {
		*sc = append(*sc, path)
	}
	return nil
}
Example #6
0
func (p *Propolis) SetRequestMetaData(req *http.Request, info *os.FileInfo) {
	// file permissions: grant "public-read" if the file grants world read permission
	if info.Permission()&s_iroth != 0 {
		req.Header.Set("X-Amz-Acl", acl_public)
	} else {
		req.Header.Set("X-Amz-Acl", acl_private)
	}

	// user id: store the numeric and symbolic names
	user, err := user.LookupId(info.Uid)
	if err != nil {
		req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d", info.Uid))
	} else {
		req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d (%s)", info.Uid, user.Username))
	}

	// group id: just store the numeric id for now until Go supports looking up group names
	req.Header.Set("X-Amz-Meta-Gid", fmt.Sprintf("%d", info.Gid))

	// store the permissions as an octal number
	req.Header.Set("X-Amz-Meta-Mode", fmt.Sprintf("0%o", info.Mode))

	// store the modified date in a nice format
	sec := info.Mtime_ns / 1e9
	ns := info.Mtime_ns % 1e9
	date := time.SecondsToLocalTime(sec).String()
	if ns == 0 {
		req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d (%s)", sec, date))
	} else {
		req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d.%09d (%s)", sec, ns, date))
	}

	// set the content-type by looking up the MIME type
	mimetype := default_mime_type
	switch {
	case info.IsDirectory():
		mimetype = directory_mime_type
	case info.IsSymlink():
		mimetype = symlink_mime_type
	default:
		if dot := strings.LastIndex(info.Name, "."); dot >= 0 && dot+1 < len(info.Name) {
			extension := strings.ToLower(info.Name[dot:])
			if kind := mime.TypeByExtension(extension); kind != "" {
				mimetype = kind
			}
		}
	}
	req.Header.Set("Content-Type", mimetype)
}
Example #7
0
func symbol(f *os.FileInfo) (s string) {
	switch {
	case f.IsDirectory():
		s = "/"
	case f.IsFifo():
		s = "|"
	case f.IsSocket():
		s = "="
	case f.IsSymlink():
		target, err := os.Readlink(f.Name)
		Errhandler(err)
		s = " -> " + target
	}
	return
}
Example #8
0
func getEntryTypeString(e *os.FileInfo) string {
	if e.IsDirectory() {
		return "/"
	} else if e.IsBlock() {
		return "<>"
	} else if e.IsFifo() {
		return ">>"
	} else if e.IsSymlink() {
		return "@"
	} else if e.IsSocket() {
		return "&"
	} else if e.IsRegular() && (e.Mode&0001 == 0001) {
		return "*"
	}
	return ""
}
Example #9
0
// createChild() creates a child for given as FsNode as child of 'parent'.  The
// resulting inode will have its lookupCount incremented.
func (me *FileSystemConnector) createChild(parent *Inode, name string, fi *os.FileInfo, fsi FsNode) (out *EntryOut) {
	parent.treeLock.Lock()
	defer parent.treeLock.Unlock()

	child := fsi.Inode()
	if child == nil {
		child = parent.createChild(name, fi.IsDirectory(), fsi)
	} else {
		parent.addChild(name, child)
	}
	me.lookupUpdate(child)

	out = parent.mount.fileInfoToEntry(fi)
	out.Ino = child.nodeId
	out.NodeId = child.nodeId
	return out
}
Example #10
0
File: path.go Project: ssrl/go
func walk(path string, f *os.FileInfo, v Visitor, errors chan<- os.Error) {
	if !f.IsDirectory() {
		v.VisitFile(path, f)
		return
	}

	if !v.VisitDir(path, f) {
		return // skip directory entries
	}

	list, err := readDir(path)
	if err != nil {
		if errors != nil {
			errors <- err
		}
	}

	for _, e := range list {
		walk(Join(path, e.Name), e, v, errors)
	}
}
Example #11
0
func (me *pathInode) findChild(fi *os.FileInfo, name string, fullPath string) (out *pathInode) {
	if fi.Ino > 0 {
		unlock := me.RLockTree()
		v := me.pathFs.clientInodeMap[fi.Ino]
		if len(v) > 0 {
			out = v[0].node

			if fi.Nlink == 1 {
				log.Println("Found linked inode, but Nlink == 1", fullPath)
			}
		}
		unlock()
	}

	if out == nil {
		out = me.createChild(fi.IsDirectory())
		out.clientInode = fi.Ino
		me.addChild(name, out)
	}

	return out
}
func itemType(fi *os.FileInfo) string {
	if fi.IsDirectory() {
		return "1"
	}
	name := fi.Name
	switch {
	case strings.HasPrefix(name, ".html"):
		return "h"
	case strings.HasPrefix(name, ".txt"):
		return "0"
	case strings.HasPrefix(name, ".gif"):
		return "g"
	case strings.HasPrefix(name, ".png"),
		strings.HasPrefix(name, ".jpg"),
		strings.HasPrefix(name, ".jpeg"):
		// TODO(bradfitz): re-encode pngs to gifs :)
		// For now, though:
		return "I" // Image file of unspecified format. Client decides
		// how to display. Often used for JPEG images
	}
	return "9" // binary file
}
Example #13
0
func isPkgDir(f *os.FileInfo) bool {
	return f.IsDirectory() && len(f.Name) > 0 && f.Name[0] != '_'
}
Example #14
0
func main() {
	var rr *http.Response
	var myreader multipart.Reader

	syscall.Umask(0000)

	if !parseME() {
		os.Exit(1)
	}

	var requesturl string

	requesturl = ("http://" + (*camera_ip) + ":" + strconv.Itoa(*camera_port) + "/mjpg/1/video.mjpg")
	fmt.Println("request sent to " + requesturl)
	rr, _, _ = http.Get(requesturl)
	myreader, _ = MultipartReader(rr)

	var p *multipart.Part

	var curr_length int = 0

	var templen int
	var buff []byte
	var s string
	var m int

	var info *os.FileInfo
	var err os.Error

	info, err = os.Lstat(*save_folder)
	if err != nil {
		fmt.Println("Folder " + (*save_folder) + " Is problematic")
		fmt.Println(err.String())
		os.Exit(1)
	}

	if !info.IsDirectory() {
		fmt.Println("Folder " + (*save_folder) + " Is not a directory")
		os.Exit(1)
	}

	var foldertime *time.Time = nil
	var foldersecs int64
	var folderstamp string

	var tstamp_secs int64
	var tstamp_nsecs int64

	var msecs int64
	var update bool
	var foldername string
	var imagename string
	var mywriter *os.File

	for i := 0; i < 1; {

		p, _ = myreader.NextPart()

		update = false

		tstamp_secs, tstamp_nsecs, _ = os.Time()
		if foldertime == nil {
			foldertime = time.SecondsToLocalTime(tstamp_secs)
			foldersecs = tstamp_secs
			update = true
		} else {
			if tstamp_secs > foldersecs {
				foldertime = time.SecondsToLocalTime(tstamp_secs)
				foldersecs = tstamp_secs
				update = true
			}

		}

		if update {
			folderstamp = strconv.Itoa64(foldertime.Year) + "_" +
				strconv.Itoa(foldertime.Month) + "_" +
				strconv.Itoa(foldertime.Day) + "_" +
				strconv.Itoa(foldertime.Hour) + "_" +
				strconv.Itoa(foldertime.Minute) + "_" +
				strconv.Itoa(foldertime.Second)
			foldername = (*save_folder) + "/" + (*camera_name) + "_" + folderstamp
			err = os.Mkdir(foldername, 0700)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error creating %s because : %s\n", foldername, err.String())
				os.Exit(1)
			}
		}

		templen, _ = strconv.Atoi(p.Header["Content-Length"])

		if templen > curr_length {
			curr_length = templen
			buff = make([]byte, curr_length)
		}

		for counter := 0; counter < templen; {
			m, _ = p.Read(buff[counter:templen])
			counter += m
		}

		p.Close()
		msecs = tstamp_nsecs / 1e6
		imagename = "image_" + folderstamp + "_" + strconv.Itoa64(msecs) + ".jpg"
		s = foldername + "/" + imagename

		mywriter, err = os.Open(s, os.O_CREAT|os.O_WRONLY, 0600)

		if err != nil {
			fmt.Fprintf(os.Stderr, "error writing %d bytes because : %s\n", templen, err.String())
			os.Exit(1)
		}

		for counter := 0; counter < templen; {
			m, _ = mywriter.Write(buff[counter:templen])
			counter += m
		}
	}
}
Example #15
0
func isPackageDir(fileInIt *os.FileInfo) bool {
	return !fileInIt.IsDirectory() && utils.IsGoFile(fileInIt.Name)
}