Add folder rename detection (#3817)

This commit is contained in:
WithoutPants
2023-07-11 11:53:49 +10:00
committed by GitHub
parent 5c38836ade
commit 93b41fb650
4 changed files with 287 additions and 13 deletions

View File

@@ -5,8 +5,10 @@ import (
"database/sql"
"errors"
"fmt"
"io/fs"
"path/filepath"
"strings"
"time"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
@@ -713,6 +715,31 @@ func (qb *FileStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]
return qb.getMany(ctx, q)
}
// FindByFileInfo finds files that match the base name, size, and mod time of the given file.
func (qb *FileStore) FindByFileInfo(ctx context.Context, info fs.FileInfo, size int64) ([]file.File, error) {
table := qb.table()
modTime := info.ModTime().Format(time.RFC3339)
q := qb.selectDataset().Prepared(true).Where(
table.Col("basename").Eq(info.Name()),
table.Col("size").Eq(size),
table.Col("mod_time").Eq(modTime),
)
return qb.getMany(ctx, q)
}
func (qb *FileStore) CountByFolderID(ctx context.Context, folderID file.FolderID) (int, error) {
table := qb.table()
q := qb.countDataset().Prepared(true).Where(
table.Col("parent_folder_id").Eq(folderID),
)
return count(ctx, q)
}
func (qb *FileStore) IsPrimary(ctx context.Context, fileID file.ID) (bool, error) {
joinTables := []exp.IdentifierExpression{
scenesFilesJoinTable,