Beispiel #1
0
func (p *Propolis) GetFileInfo(elt *File) (err os.Error) {
	var stmt *sqlite.Stmt
	stmt, err = p.Db.Prepare("SELECT md5, uid, gid, mode, mtime, size " +
		"FROM cache WHERE path = ?")
	if err != nil {
		return
	}
	defer stmt.Finalize()
	if err = stmt.Exec(elt.ServerPath); err != nil || !stmt.Next() {
		return
	}
	elt.CacheInfo = new(os.FileInfo)
	elt.CacheInfo.Name = elt.ServerPath
	var mode int64
	err = stmt.Scan(
		&elt.CacheHashHex,
		&elt.CacheInfo.Uid,
		&elt.CacheInfo.Gid,
		&mode,
		&elt.CacheInfo.Mtime_ns,
		&elt.CacheInfo.Size)
	elt.CacheInfo.Mode = uint32(mode)
	return
}
Beispiel #2
0
func (p *Propolis) GetPathFromMd5(elt *File) (path string, err os.Error) {
	var stmt1, stmt2 *sqlite.Stmt
	stmt1, err = p.Db.Prepare("SELECT path FROM cache WHERE md5 = ? AND path = ?")
	if err != nil {
		return
	}
	defer stmt1.Finalize()
	if err = stmt1.Exec(elt.LocalHashHex, elt.ServerPath); err != nil {
		return
	}
	if stmt1.Next() {
		// this path has the desired md5 hash
		return elt.ServerPath, nil
	}
	stmt2, err = p.Db.Prepare("SELECT path FROM cache WHERE md5 = ? LIMIT 1")
	if err != nil {
		return
	}
	defer stmt2.Finalize()
	if err = stmt2.Exec(elt.LocalHashHex); err != nil || !stmt2.Next() {
		return
	}
	err = stmt2.Scan(&path)
	return
}
Beispiel #3
0
func (p *Propolis) ScanCache(push bool) (err os.Error) {
	// scan the entire cache
	var stmt *sqlite.Stmt
	prefix := p.BucketRoot
	if prefix != "" {
		prefix = strings.Replace(prefix, "\\", "\\\\", -1)
		prefix = strings.Replace(prefix, "_", "\\_", -1)
		prefix = strings.Replace(prefix, "%", "\\%", -1)
		prefix += "/%"
		stmt, err = p.Db.Prepare("SELECT * FROM cache WHERE path LIKE ? ESCAPE '\\'")
	} else {
		stmt, err = p.Db.Prepare("SELECT * FROM cache")
	}
	if err != nil {
		return
	}
	defer stmt.Finalize()
	if prefix != "" {
		if err = stmt.Exec(prefix); err != nil {
			return
		}
	} else {
		if err = stmt.Exec(); err != nil {
			return
		}
	}

	// read the results
	for stmt.Next() {
		info := new(os.FileInfo)
		var mode int64
		var hashHex string
		err = stmt.Scan(
			&info.Name,
			&hashHex,
			&info.Uid,
			&info.Gid,
			&mode,
			&info.Mtime_ns,
			&info.Size)
		if err != nil {
			return
		}
		info.Mode = uint32(mode)

		// see if we have a matching entry already
		var elt *File
		var present bool
		if elt, present = p.Catalog[info.Name]; !present {
			elt = p.NewFileServer(info.Name, push)
		}
		elt.CacheInfo = info
		elt.CacheHashHex = hashHex

		// store the result (if it's not already there)
		p.Catalog[info.Name] = elt
	}
	return
}