Compare commits

...

2 Commits

2 changed files with 34 additions and 6 deletions

View File

@ -38,12 +38,19 @@ func (blefs *FS) removeAllChildren(path string) error {
}
for _, entry := range list {
if entry.IsDir() {
err = blefs.removeAllChildren(filepath.Join(path, entry.Name()))
} else {
err = blefs.Remove(path)
name := entry.Name()
if name == "." || name == ".." {
continue
}
if err != nil {
entryPath := filepath.Join(path, name)
if entry.IsDir() {
err = blefs.removeAllChildren(entryPath)
} else {
err = blefs.Remove(entryPath)
}
if err != nil && err.(FSError).Code != -2 {
return err
}
}
@ -58,7 +65,7 @@ func (blefs *FS) MkdirAll(path string) error {
splitPath := strings.Split(path, "/")
for i := 1; i < len(splitPath); i++ {
curPath := strings.Join(splitPath[0:i], "/")
curPath := strings.Join(splitPath[0:i+1], "/")
err := blefs.Mkdir(curPath)
if err != nil && err.(FSError).Code != -17 {

View File

@ -77,12 +77,16 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return nil, err
}
log.Debug().Msg("Decoded manifest file")
go func() {
defer close(out)
for _, file := range manifest.Obsolete {
name := filepath.Base(file.Path)
log.Debug().Str("file", file.Path).Msg("Removing file")
err := fs.RemoveAll(file.Path)
if err != nil {
out <- ResourceLoadProgress{
@ -93,6 +97,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().Str("file", file.Path).Msg("Removed file")
out <- ResourceLoadProgress{
Name: name,
Operation: ResourceOperationRemoveObsolete,
@ -121,8 +127,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().Str("file", file.Path).Msg("Making directories")
err = fs.MkdirAll(filepath.Dir(file.Path))
if err != nil {
log.Debug().Err(err).Msg("Error making directories")
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,
@ -132,8 +141,14 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().
Str("file", file.Path).
Int64("size", srcFi.Size()).
Msg("Creating file")
dst, err := fs.Create(file.Path, uint32(srcFi.Size()))
if err != nil {
log.Debug().Err(err).Msg("Error creating file")
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,
@ -146,6 +161,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
progCh := dst.Progress()
go func() {
for sent := range progCh {
log.Debug().
Int64("total", srcFi.Size()).
Uint32("sent", sent).
Msg("Progress event sent")
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,
@ -161,6 +181,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
n, err := io.Copy(dst, src)
if err != nil {
log.Debug().Err(err).Msg("Error writing to file")
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,