mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Handle modified files where the case of the filename changed on case-insensitive filesystems (#6327)
* Find existing files with case insensitivity if filesystem is case insensitive * Handle case change in folders * Optimise to only test file system case sensitivity if the first query found nothing This limits the overhead to new paths, and adds an extra query for new paths to windows installs
This commit is contained in:
@@ -625,9 +625,9 @@ func (qb *FileStore) find(ctx context.Context, id models.FileID) (models.File, e
|
||||
}
|
||||
|
||||
// FindByPath returns the first file that matches the given path. Wildcard characters are supported.
|
||||
func (qb *FileStore) FindByPath(ctx context.Context, p string) (models.File, error) {
|
||||
func (qb *FileStore) FindByPath(ctx context.Context, p string, caseSensitive bool) (models.File, error) {
|
||||
|
||||
ret, err := qb.FindAllByPath(ctx, p)
|
||||
ret, err := qb.FindAllByPath(ctx, p, caseSensitive)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -642,7 +642,7 @@ func (qb *FileStore) FindByPath(ctx context.Context, p string) (models.File, err
|
||||
|
||||
// FindAllByPath returns all the files that match the given path.
|
||||
// Wildcard characters are supported.
|
||||
func (qb *FileStore) FindAllByPath(ctx context.Context, p string) ([]models.File, error) {
|
||||
func (qb *FileStore) FindAllByPath(ctx context.Context, p string, caseSensitive bool) ([]models.File, error) {
|
||||
// separate basename from path
|
||||
basename := filepath.Base(p)
|
||||
dirName := filepath.Dir(p)
|
||||
@@ -657,7 +657,7 @@ func (qb *FileStore) FindAllByPath(ctx context.Context, p string) ([]models.File
|
||||
// like uses case-insensitive matching. Only use like if wildcards are used
|
||||
q := qb.selectDataset().Prepared(true)
|
||||
|
||||
if strings.Contains(basename, "%") || strings.Contains(dirName, "%") {
|
||||
if strings.Contains(basename, "%") || strings.Contains(dirName, "%") || !caseSensitive {
|
||||
q = q.Where(
|
||||
folderTable.Col("path").Like(dirName),
|
||||
table.Col("basename").Like(basename),
|
||||
|
||||
Reference in New Issue
Block a user