Add more things for file handling
This commit is contained in:
parent
c813c4784a
commit
1fcf47bffc
14 changed files with 284 additions and 59 deletions
|
@ -18,7 +18,10 @@ import (
|
|||
// All files without matching metadata will be deleted. Same for all metadata without a matching file.
|
||||
// No attempt at restoring a connection will be made
|
||||
func (s *Server) ServiceEnsureFileSynchronisation() {
|
||||
allFiles, err := dbgen.MediaMetadata.Select(dbgen.MediaMetadata.ID, dbgen.MediaMetadata.OwnedById, dbgen.MediaMetadata.Name).
|
||||
mm := dbgen.MediaMetadata
|
||||
allFiles, err := mm.
|
||||
Select(mm.ID, mm.OwnedById, mm.Name, mm.Location).
|
||||
Where(mm.Location.NotLike("linstrom://%"), mm.Remote.Is(false)).
|
||||
Find()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get a list of all known media")
|
||||
|
@ -27,9 +30,12 @@ func (s *Server) ServiceEnsureFileSynchronisation() {
|
|||
foundInDb := []string{}
|
||||
objectMissingInDb := []minio.ObjectInfo{}
|
||||
// Go over all objects in the bucket. Note down if it has an entry in the db or not
|
||||
for obj := range s.client.ListObjects(context.TODO(), config.GlobalConfig.S3.BucketName, minio.ListObjectsOptions{}) {
|
||||
for obj := range s.client.ListObjects(context.TODO(), config.GlobalConfig.S3.BucketName, minio.ListObjectsOptions{
|
||||
Recursive: true,
|
||||
}) {
|
||||
log.Debug().Str("object-key", obj.Key).Msg("Checking object")
|
||||
if slices.ContainsFunc(allFiles, func(e *models.MediaMetadata) bool {
|
||||
return UsernameFilename(e.OwnedById.String, e.Name) == obj.Key
|
||||
return e.Location == obj.Key
|
||||
}) {
|
||||
foundInDb = append(foundInDb, obj.Key)
|
||||
} else {
|
||||
|
@ -41,7 +47,7 @@ func (s *Server) ServiceEnsureFileSynchronisation() {
|
|||
entryMissingAnObject := []string{}
|
||||
for _, dbFile := range allFiles {
|
||||
if !slices.ContainsFunc(foundInDb, func(e string) bool {
|
||||
return UsernameFilename(dbFile.OwnedById.String, dbFile.Name) == e
|
||||
return dbFile.Location == e
|
||||
}) {
|
||||
entryMissingAnObject = append(entryMissingAnObject, dbFile.ID)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue