コード例 #1
0
ファイル: cli.go プロジェクト: logtcn/TMSU
func Run() {
	helpCommands = commands

	parser := NewOptionParser(globalOptions, commands)
	command, options, arguments, err := parser.Parse(os.Args[1:]...)
	if err != nil {
		log.Fatal(err)
	}

	switch {
	case options.HasOption("--version"):
		command = findCommand(commands, "version")
	case options.HasOption("--help"), command == nil:
		command = findCommand(commands, "help")
	}

	log.Verbosity = options.Count("--verbose") + 1

	var databasePath string
	switch {
	case options.HasOption("--database"):
		databasePath = options.Get("--database").Argument
	case os.Getenv("TMSU_DB") != "":
		databasePath = os.Getenv("TMSU_DB")
	default:
		databasePath, err = findDatabase()
		if err != nil {
			log.Fatalf("could not find database: %v", err)
		}
	}

	err, warnings := command.Exec(options, arguments, databasePath)

	if warnings != nil {
		for _, warning := range warnings {
			log.Warn(warning)
		}
	}

	if err != nil {
		log.Warn(err.Error())
	}

	if err != nil || (warnings != nil && len(warnings) > 0) {
		os.Exit(1)
	}
}
コード例 #2
0
ファイル: fusevfs.go プロジェクト: logtcn/TMSU
func (vfs FuseVfs) Unlink(name string, context *fuse.Context) fuse.Status {
	log.Infof(2, "BEGIN Unlink(%v)", name)
	defer log.Infof(2, "END Unlink(%v)", name)

	tx, err := vfs.store.Begin()
	if err != nil {
		log.Fatalf("could not begin transaction: %v", err)
	}
	defer tx.Commit()

	fileId := vfs.parseFileId(name)
	if fileId == 0 {
		// can only unlink file symbolic links
		return fuse.EPERM
	}

	file, err := vfs.store.File(tx, fileId)
	if err != nil {
		log.Fatal("could not retrieve file '%v': %v", fileId, err)
	}
	if file == nil {
		// reply ok if file doesn't exist otherwise recursive deletes fail
		return fuse.OK
	}
	path := vfs.splitPath(name)

	switch path[0] {
	case tagsDir:
		dirName := path[len(path)-2]

		var tagName, valueName string
		if dirName[0] == '=' {
			tagName = path[len(path)-3]
			valueName = dirName[1:len(dirName)]
		} else {
			tagName = dirName
			valueName = ""
		}

		tag, err := vfs.store.TagByName(tx, tagName)
		if err != nil {
			log.Fatal(err)
		}
		if tag == nil {
			log.Fatalf("could not retrieve tag '%v'.", tagName)
		}

		value, err := vfs.store.ValueByName(tx, valueName)
		if err != nil {
			log.Fatal(err)
		}
		if value == nil {
			log.Fatalf("could not retrieve value '%v'.", valueName)
		}

		if err = vfs.store.DeleteFileTag(tx, fileId, tag.Id, value.Id); err != nil {
			log.Fatal(err)
		}

		if err := tx.Commit(); err != nil {
			log.Fatalf("could not commit transaction: %v", err)
		}

		return fuse.OK
	case queriesDir:
		return fuse.EPERM
	}

	return fuse.ENOSYS
}