forked from Elara6331/infinitime
Add debug logging to resource loading
This commit is contained in:
parent
b476853dc0
commit
01970b2bb7
21
resources.go
21
resources.go
@ -77,12 +77,16 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Msg("Decoded manifest file")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
|
|
||||||
for _, file := range manifest.Obsolete {
|
for _, file := range manifest.Obsolete {
|
||||||
name := filepath.Base(file.Path)
|
name := filepath.Base(file.Path)
|
||||||
|
|
||||||
|
log.Debug().Str("file", file.Path).Msg("Removing file")
|
||||||
|
|
||||||
err := fs.RemoveAll(file.Path)
|
err := fs.RemoveAll(file.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
@ -93,6 +97,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Str("file", file.Path).Msg("Removed file")
|
||||||
|
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
Name: name,
|
Name: name,
|
||||||
Operation: ResourceOperationRemoveObsolete,
|
Operation: ResourceOperationRemoveObsolete,
|
||||||
@ -121,8 +127,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Str("file", file.Path).Msg("Making directories")
|
||||||
|
|
||||||
err = fs.MkdirAll(filepath.Dir(file.Path))
|
err = fs.MkdirAll(filepath.Dir(file.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug().Err(err).Msg("Error making directories")
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
Name: file.Name,
|
Name: file.Name,
|
||||||
Operation: ResourceOperationUpload,
|
Operation: ResourceOperationUpload,
|
||||||
@ -132,8 +141,14 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().
|
||||||
|
Str("file", file.Path).
|
||||||
|
Int64("size", srcFi.Size()).
|
||||||
|
Msg("Creating file")
|
||||||
|
|
||||||
dst, err := fs.Create(file.Path, uint32(srcFi.Size()))
|
dst, err := fs.Create(file.Path, uint32(srcFi.Size()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug().Err(err).Msg("Error creating file")
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
Name: file.Name,
|
Name: file.Name,
|
||||||
Operation: ResourceOperationUpload,
|
Operation: ResourceOperationUpload,
|
||||||
@ -146,6 +161,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
progCh := dst.Progress()
|
progCh := dst.Progress()
|
||||||
go func() {
|
go func() {
|
||||||
for sent := range progCh {
|
for sent := range progCh {
|
||||||
|
log.Debug().
|
||||||
|
Int64("total", srcFi.Size()).
|
||||||
|
Uint32("sent", sent).
|
||||||
|
Msg("Progress event sent")
|
||||||
|
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
Name: file.Name,
|
Name: file.Name,
|
||||||
Operation: ResourceOperationUpload,
|
Operation: ResourceOperationUpload,
|
||||||
@ -161,6 +181,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
|
|||||||
|
|
||||||
n, err := io.Copy(dst, src)
|
n, err := io.Copy(dst, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug().Err(err).Msg("Error writing to file")
|
||||||
out <- ResourceLoadProgress{
|
out <- ResourceLoadProgress{
|
||||||
Name: file.Name,
|
Name: file.Name,
|
||||||
Operation: ResourceOperationUpload,
|
Operation: ResourceOperationUpload,
|
||||||
|
Loading…
Reference in New Issue
Block a user