Skip to content
Snippets Groups Projects
Commit dc85a595 authored by Christian Pointner's avatar Christian Pointner
Browse files

set source hash in store

parent 66b917a0
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,9 @@ func (job *Job) fetch() error { ...@@ -105,7 +105,9 @@ func (job *Job) fetch() error {
hash := sha256.New() hash := sha256.New()
src := io.TeeReader(job.source.r, hash) src := io.TeeReader(job.source.r, hash)
written, err := io.Copy(&progressWriter{job, 0, conv}, src) written, err := io.Copy(&progressWriter{job, 0, conv}, src)
job.im.dbgLog.Printf("fetch(): done copying %d bytes from source (SHA256: %s)", written, hex.EncodeToString(hash.Sum(nil))) hashHex := hex.EncodeToString(hash.Sum(nil))
job.im.dbgLog.Printf("fetch(): done copying %d bytes from source (SHA256: %s)", written, hashHex)
job.im.store.UpdateFileSourceHash(job.Group, job.ID, "sha256:"+hashHex)
done <- err done <- err
}() }()
......
...@@ -100,6 +100,14 @@ func (st *Store) UpdateFileImportState(group string, id uint64, state ImportStat ...@@ -100,6 +100,14 @@ func (st *Store) UpdateFileImportState(group string, id uint64, state ImportStat
return file, nil return file, nil
} }
func (st *Store) UpdateFileSourceHash(group string, id uint64, hash string) (*File, error) {
file := &File{ID: id}
if err := st.db.Model(&file).Where("group_name = ?", group).Update("source__hash", hash).Error; err != nil {
return nil, err
}
return file, nil
}
func (st *Store) getFileUsage(id uint64, playlists *Playlists) (err error) { func (st *Store) getFileUsage(id uint64, playlists *Playlists) (err error) {
sub := st.db.Model(PlaylistEntry{}).Select("playlist_id").Where("file_id = ?", id).Group("playlist_id").SubQuery() sub := st.db.Model(PlaylistEntry{}).Select("playlist_id").Where("file_id = ?", id).Group("playlist_id").SubQuery()
err = st.db.Where("id in ?", sub).Find(playlists).Error err = st.db.Where("id in ?", sub).Find(playlists).Error
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment