本文整理匯總了Golang中github.com/oniony/TMSU/common/log.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OpenDir
func (vfs FuseVfs) OpenDir(name string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN OpenDir(%v)", name)
defer log.Infof(2, "END OpenDir(%v)", name)
tx, err := vfs.store.Begin()
if err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
defer tx.Commit()
switch name {
case "":
return vfs.topFiles()
case tagsDir:
return vfs.tagDirectories(tx)
case queriesDir:
return vfs.queriesDirectories(tx)
}
path := vfs.splitPath(name)
switch path[0] {
case tagsDir:
return vfs.openTaggedEntryDir(tx, path[1:])
case queriesDir:
return vfs.openQueryEntryDir(tx, path[1:])
}
return nil, fuse.ENOENT
}
示例2: tagDirectories
func (vfs FuseVfs) tagDirectories(tx *storage.Tx) ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN tagDirectories")
defer log.Infof(2, "END tagDirectories")
tags, err := vfs.store.Tags(tx)
if err != nil {
log.Fatalf("Could not retrieve tags: %v", err)
}
entries := make([]fuse.DirEntry, 0, len(tags))
for _, tag := range tags {
if strings.ContainsAny(tag.Name, "/\\") {
log.Infof(2, "Tag '%v' contains slashes so is omitted from the VFS")
continue
}
entries = append(entries, fuse.DirEntry{Name: tag.Name, Mode: fuse.S_IFDIR})
}
// show help file until there are three tags
if len(tags) < 3 {
entries = append(entries, fuse.DirEntry{Name: helpFilename, Mode: fuse.S_IFREG})
}
return entries, fuse.OK
}
示例3: getQueryAttr
func (vfs FuseVfs) getQueryAttr() (*fuse.Attr, fuse.Status) {
log.Infof(2, "BEGIN getQueryAttr")
defer log.Infof(2, "END getQueryAttr")
now := time.Now()
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755, Nlink: 2, Size: 0, Mtime: uint64(now.Unix()), Mtimensec: uint32(now.Nanosecond())}, fuse.OK
}
示例4: statusCheckFile
func statusCheckFile(absPath string, file *entities.File, report *StatusReport) error {
log.Infof(2, "%v: checking file status.", absPath)
stat, err := os.Stat(file.Path())
if err != nil {
switch {
case os.IsNotExist(err):
log.Infof(2, "%v: file is missing.", absPath)
report.AddRow(Row{absPath, MISSING})
return nil
case os.IsPermission(err):
log.Warnf("%v: permission denied.", absPath)
case strings.Contains(err.Error(), "not a directory"): //TODO improve
report.AddRow(Row{file.Path(), MISSING})
return nil
default:
return fmt.Errorf("%v: could not stat: %v", file.Path(), err)
}
} else {
if stat.Size() != file.Size || !stat.ModTime().UTC().Equal(file.ModTime) {
log.Infof(2, "%v: file is modified.", absPath)
report.AddRow(Row{absPath, MODIFIED})
} else {
log.Infof(2, "%v: file is unchanged.", absPath)
report.AddRow(Row{absPath, TAGGED})
}
}
return nil
}
示例5: determineStatuses
func determineStatuses(dbFiles entities.Files) (unmodified, modified, missing entities.Files) {
log.Infof(2, "determining file statuses")
unmodified = make(entities.Files, 0, 10)
modified = make(entities.Files, 0, 10)
missing = make(entities.Files, 0, 10)
for _, dbFile := range dbFiles {
stat, err := os.Stat(dbFile.Path())
if err != nil {
switch {
case os.IsPermission(err):
//TODO return as warning
log.Warnf("%v: permission denied", dbFile.Path())
continue
case os.IsNotExist(err):
//TODO return as warning
log.Infof(2, "%v: missing", dbFile.Path())
missing = append(missing, dbFile)
continue
}
}
if dbFile.ModTime.Equal(stat.ModTime().UTC()) && dbFile.Size == stat.Size() {
log.Infof(2, "%v: unmodified", dbFile.Path())
unmodified = append(unmodified, dbFile)
} else {
log.Infof(2, "%v: modified", dbFile.Path())
modified = append(modified, dbFile)
}
}
return
}
示例6: Mkdir
func (vfs FuseVfs) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Mkdir(%v)", name)
defer log.Infof(2, "END Mkdir(%v)", name)
path := vfs.splitPath(name)
if len(path) != 2 {
return fuse.EPERM
}
tx, err := vfs.store.Begin()
if err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
defer tx.Commit()
switch path[0] {
case tagsDir:
name := path[1]
if _, err := vfs.store.AddTag(tx, name); err != nil {
log.Fatalf("could not create tag '%v': %v", name, err)
}
if err := tx.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
return fuse.OK
case queriesDir:
return fuse.EINVAL
}
return fuse.ENOSYS
}
示例7: GetAttr
func (vfs FuseVfs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
log.Infof(2, "BEGIN GetAttr(%v)", name)
defer log.Infof(2, "END GetAttr(%v)", name)
switch name {
case databaseFilename:
return vfs.getDatabaseFileAttr()
case "":
fallthrough
case tagsDir:
return vfs.getTagsAttr()
case queriesDir:
return vfs.getQueryAttr()
}
path := vfs.splitPath(name)
switch path[0] {
case tagsDir:
return vfs.getTaggedEntryAttr(path[1:])
case queriesDir:
return vfs.getQueryEntryAttr(path[1:])
}
return nil, fuse.ENOENT
}
示例8: repairMoved
func repairMoved(store *storage.Storage, tx *storage.Tx, missing entities.Files, searchPaths []string, pretend bool, settings entities.Settings) error {
log.Infof(2, "repairing moved files")
if len(missing) == 0 || len(searchPaths) == 0 {
// don't bother enumerating filesystem if nothing to do
return nil
}
pathsBySize, err := buildPathBySizeMap(searchPaths)
if err != nil {
return err
}
for index, dbFile := range missing {
log.Infof(2, "%v: searching for new location", dbFile.Path())
pathsOfSize := pathsBySize[dbFile.Size]
log.Infof(2, "%v: file is of size %v, identified %v files of this size", dbFile.Path(), dbFile.Size, len(pathsOfSize))
for _, candidatePath := range pathsOfSize {
candidateFile, err := store.FileByPath(tx, candidatePath)
if err != nil {
return err
}
if candidateFile != nil {
// file is already tagged
continue
}
stat, err := os.Stat(candidatePath)
if err != nil {
return fmt.Errorf("%v: could not stat file: %v", candidatePath, err)
}
fingerprint, err := fingerprint.Create(candidatePath, settings.FileFingerprintAlgorithm(), settings.DirectoryFingerprintAlgorithm(), settings.SymlinkFingerprintAlgorithm())
if err != nil {
return fmt.Errorf("%v: could not create fingerprint: %v", candidatePath, err)
}
if fingerprint == dbFile.Fingerprint {
if !pretend {
_, err := store.UpdateFile(tx, dbFile.Id, candidatePath, dbFile.Fingerprint, stat.ModTime(), dbFile.Size, dbFile.IsDir)
if err != nil {
return fmt.Errorf("%v: could not update file in database: %v", dbFile.Path(), err)
}
}
fmt.Printf("%v: updated path to %v\n", dbFile.Path(), candidatePath)
missing[index] = nil
break
}
}
}
return nil
}
示例9: untagPathsAll
func untagPathsAll(store *storage.Storage, tx *storage.Tx, paths []string, recursive, followSymlinks bool) (error, warnings) {
warnings := make(warnings, 0, 10)
for _, path := range paths {
absPath, err := filepath.Abs(path)
if err != nil {
return fmt.Errorf("%v: could not get absolute path: %v", path, err), warnings
}
log.Infof(2, "%v: resolving path", path)
stat, err := os.Lstat(absPath)
if err != nil {
switch {
case os.IsNotExist(err), os.IsPermission(err):
// ignore
default:
return err, nil
}
} else if stat.Mode()&os.ModeSymlink != 0 && followSymlinks {
absPath, err = _path.Dereference(absPath)
if err != nil {
return err, nil
}
}
file, err := store.FileByPath(tx, absPath)
if err != nil {
return fmt.Errorf("%v: could not retrieve file: %v", path, err), warnings
}
if file == nil {
warnings = append(warnings, fmt.Sprintf("%v: file is not tagged.", path))
continue
}
log.Infof(2, "%v: removing all tags.", path)
if err := store.DeleteFileTagsByFileId(tx, file.Id); err != nil {
return fmt.Errorf("%v: could not remove file's tags: %v", path, err), warnings
}
if recursive {
childFiles, err := store.FilesByDirectory(tx, file.Path())
if err != nil {
return fmt.Errorf("%v: could not retrieve files for directory: %v", path, err), warnings
}
for _, childFile := range childFiles {
if err := store.DeleteFileTagsByFileId(tx, childFile.Id); err != nil {
return fmt.Errorf("%v: could not remove file's tags: %v", childFile.Path(), err), warnings
}
}
}
}
return nil, warnings
}
示例10: topFiles
func (vfs FuseVfs) topFiles() ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN topFiles")
defer log.Infof(2, "END topFiles")
entries := []fuse.DirEntry{
fuse.DirEntry{Name: databaseFilename, Mode: fuse.S_IFLNK},
fuse.DirEntry{Name: tagsDir, Mode: fuse.S_IFDIR},
fuse.DirEntry{Name: queriesDir, Mode: fuse.S_IFDIR}}
return entries, fuse.OK
}
示例11: upgrade
func upgrade(tx *sql.Tx) error {
version := currentSchemaVersion(tx)
log.Infof(2, "database schema has version %v, latest schema version is %v", version, latestSchemaVersion)
if version == latestSchemaVersion {
log.Infof(2, "schema is up to date")
return nil
}
noVersion := schemaVersion{}
if version == noVersion {
log.Infof(2, "creating schema")
if err := createSchema(tx); err != nil {
return err
}
// still need to run upgrade as per 0.5.0 database did not store a version
}
log.Infof(2, "upgrading database")
if version.LessThan(schemaVersion{common.Version{0, 5, 0}, 0}) {
log.Infof(2, "renaming fingerprint algorithm setting")
if err := renameFingerprintAlgorithmSetting(tx); err != nil {
return err
}
}
if version.LessThan(schemaVersion{common.Version{0, 6, 0}, 0}) {
log.Infof(2, "recreating implication table")
if err := recreateImplicationTable(tx); err != nil {
return err
}
}
if version.LessThan(schemaVersion{common.Version{0, 7, 0}, 0}) {
log.Infof(2, "updating fingerprint algorithms")
if err := updateFingerprintAlgorithms(tx); err != nil {
return err
}
}
if version.LessThan(schemaVersion{common.Version{0, 7, 0}, 1}) {
log.Infof(2, "recreating version table")
if err := recreateVersionTable(tx); err != nil {
return err
}
}
log.Infof(2, "updating schema version")
if err := updateSchemaVersion(tx, latestSchemaVersion); err != nil {
return err
}
return nil
}
示例12: deleteImplications
func deleteImplications(store *storage.Storage, tx *storage.Tx, tagArgs []string) (error, warnings) {
log.Infof(2, "loading settings")
implyingTagArg := tagArgs[0]
impliedTagArgs := tagArgs[1:]
implyingTagName, implyingValueName := parseTagEqValueName(implyingTagArg)
implyingTag, err := store.TagByName(tx, implyingTagName)
if err != nil {
return err, nil
}
if implyingTag == nil {
return NoSuchTagError{implyingTagName}, nil
}
implyingValue, err := store.ValueByName(tx, implyingValueName)
if err != nil {
return err, nil
}
if implyingValue == nil {
return NoSuchValueError{implyingValueName}, nil
}
warnings := make(warnings, 0, 10)
for _, impliedTagArg := range impliedTagArgs {
log.Infof(2, "removing tag implication %v -> %v.", implyingTagArg, impliedTagArg)
impliedTagName, impliedValueName := parseTagEqValueName(impliedTagArg)
impliedTag, err := store.TagByName(tx, impliedTagName)
if err != nil {
return err, warnings
}
if impliedTag == nil {
warnings = append(warnings, fmt.Sprintf("no such tag '%v'", impliedTagName))
}
impliedValue, err := store.ValueByName(tx, impliedValueName)
if err != nil {
return err, warnings
}
if impliedValue == nil {
warnings = append(warnings, fmt.Sprintf("no such value '%v'", impliedValueName))
}
if err := store.DeleteImplication(tx, entities.TagIdValueIdPair{implyingTag.Id, implyingValue.Id}, entities.TagIdValueIdPair{impliedTag.Id, impliedValue.Id}); err != nil {
return fmt.Errorf("could not delete tag implication of %v to %v: %v", implyingTagArg, impliedTagArg, err), warnings
}
}
return nil, warnings
}
示例13: Open
func (vfs FuseVfs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
log.Infof(2, "BEGIN Open(%v)", name)
defer log.Infof(2, "END Open(%v)", name)
switch name {
case filepath.Join(queriesDir, helpFilename):
return nodefs.NewDataFile([]byte(queryDirHelp)), fuse.OK
case filepath.Join(tagsDir, helpFilename):
return nodefs.NewDataFile([]byte(tagsDirHelp)), fuse.OK
}
return nil, fuse.ENOSYS
}
示例14: mergeValues
func mergeValues(store *storage.Storage, tx *storage.Tx, sourceValueNames []string, destValueName string) (error, warnings) {
destValue, err := store.ValueByName(tx, destValueName)
if err != nil {
return fmt.Errorf("could not retrieve value '%v': %v", destValueName, err), nil
}
if destValue == nil {
return fmt.Errorf("no such value '%v'", destValueName), nil
}
warnings := make(warnings, 0, 10)
for _, sourceValueName := range sourceValueNames {
if sourceValueName == destValueName {
warnings = append(warnings, fmt.Sprintf("cannot merge value '%v' into itself", sourceValueName))
continue
}
sourceValue, err := store.ValueByName(tx, sourceValueName)
if err != nil {
return fmt.Errorf("could not retrieve value '%v': %v", sourceValueName, err), warnings
}
if sourceValue == nil {
warnings = append(warnings, fmt.Sprintf("no such value '%v'", sourceValueName))
continue
}
log.Infof(2, "finding files tagged with value '%v'.", sourceValueName)
fileTags, err := store.FileTagsByValueId(tx, sourceValue.Id)
if err != nil {
return fmt.Errorf("could not retrieve files for value '%v': %v", sourceValueName, err), warnings
}
log.Infof(2, "applying value '%v' to these files.", destValueName)
for _, fileTag := range fileTags {
if _, err = store.AddFileTag(tx, fileTag.FileId, fileTag.TagId, destValue.Id); err != nil {
return fmt.Errorf("could not apply value '%v' to file #%v: %v", destValueName, fileTag.FileId, err), warnings
}
}
log.Infof(2, "deleting value '%v'.", sourceValueName)
if err = store.DeleteValue(tx, sourceValue.Id); err != nil {
return fmt.Errorf("could not delete value '%v': %v", sourceValueName, err), warnings
}
}
return nil, warnings
}
示例15: openTaggedEntryDir
func (vfs FuseVfs) openTaggedEntryDir(tx *storage.Tx, path []string) ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN openTaggedEntryDir(%v)", path)
defer log.Infof(2, "END openTaggedEntryDir(%v)", path)
expression := pathToExpression(path)
files, err := vfs.store.FilesForQuery(tx, expression, "", false, false, "name")
if err != nil {
log.Fatalf("could not query files: %v", err)
}
lastPathElement := path[len(path)-1]
var valueNames []string
if lastPathElement[0] != '=' {
tagName := unescape(lastPathElement)
valueNames, err = vfs.tagValueNamesForFiles(tx, tagName, files)
if err != nil {
log.Fatalf("could not retrieve values for '%v': %v", err)
}
} else {
valueNames = []string{}
}
furtherTagNames, err := vfs.tagNamesForFiles(tx, files)
if err != nil {
log.Fatalf("could not retrieve further tags: %v", err)
}
entries := make([]fuse.DirEntry, 0, len(files)+len(furtherTagNames))
for _, tagName := range furtherTagNames {
tagName = escape(tagName)
if !containsString(path, tagName) {
entries = append(entries, fuse.DirEntry{Name: tagName, Mode: fuse.S_IFDIR | 0755})
}
}
for _, valueName := range valueNames {
valueName = escape(valueName)
entries = append(entries, fuse.DirEntry{Name: "=" + valueName, Mode: fuse.S_IFDIR | 0755})
}
for _, file := range files {
linkName := vfs.getLinkName(file)
entries = append(entries, fuse.DirEntry{Name: linkName, Mode: fuse.S_IFLNK})
}
return entries, fuse.OK
}