mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Add folder rename detection (#3817)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user