Commits

Paul Ruane committed a335189

File that is untagged via the VFS is removed from DB when it no longer has any tags.

Comments (0)

Files changed (2)

src/tmsu/cli/untag.go

 		return fmt.Errorf("%v: could not get tag count: %v", file.Path(), err)
 	}
 
-	if filetagCount == 0 {
-		log.Infof(2, "%v: removing untagged file.", file.Path())
+	if filetagCount != 0 {
+		return nil
+	}
 
-		err = store.RemoveFile(file.Id)
-		if err != nil {
-			return fmt.Errorf("%v: could not remove file: %v", file.Path(), err)
-		}
+	log.Infof(2, "%v: removing untagged file.", file.Path())
+
+	err = store.RemoveFile(file.Id)
+	if err != nil {
+		return fmt.Errorf("%v: could not remove file: %v", file.Path(), err)
 	}
 
 	return nil

src/tmsu/vfs/fusevfs.go

 			}
 		}
 
+		if err := vfs.removeUntaggedFile(fileId); err != nil {
+			log.Fatal(err)
+		}
+
 		return fuse.OK
 	}
 
 func (vfs FuseVfs) saveQuery(query string) {
 }
 
+func (vfs FuseVfs) removeUntaggedFile(fileId uint) error {
+	filetagCount, err := vfs.store.FileTagCountByFileId(fileId)
+	if err != nil {
+		return fmt.Errorf("could not get tag count: %v", err)
+	}
+
+	if filetagCount != 0 {
+		return nil
+	}
+
+	if err := vfs.store.RemoveFile(fileId); err != nil {
+		return fmt.Errorf("could not remove file: %v", err)
+	}
+
+	return nil
+}
+
 func uitoa(ui uint) string {
 	return strconv.FormatUint(uint64(ui), 10)
 }