fix(history-archive): Skip dowloading data from torrent if free space is not enought (#4449)

This commit is contained in:
Boris Melnik 2023-12-14 12:52:10 +03:00 committed by GitHub
parent 42cf9fa740
commit af9d3bc7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -43,3 +43,4 @@ var ErrCannotBanOwnerOrAdmin = errors.New("not allowed to ban admin or owner")
var ErrInvalidManageTokensPermission = errors.New("no privileges to manage tokens")
var ErrRevealedAccountsAbsent = errors.New("revealed accounts is absent")
var ErrNoRevealedAccountsSignature = errors.New("revealed accounts without the signature")
var ErrNoFreeSpaceForHistoryArchives = errors.New("history archive: No free space for downloading history archives")

View File

@ -11,6 +11,7 @@ import (
"sort"
"strings"
"sync"
"syscall"
"time"
"github.com/anacrolix/torrent"
@ -3972,6 +3973,22 @@ func (m *Manager) SeedHistoryArchiveTorrent(communityID types.HexBytes) error {
if err != nil {
return err
}
var stat syscall.Statfs_t
wd, _ := os.Getwd()
err = syscall.Statfs(wd, &stat)
if err != nil {
return err
}
// Available blocks * size per block = available space in bytes
freeSpace := stat.Bavail * uint64(stat.Bsize)
if freeSpace <= uint64(torrent.Length()) {
return ErrNoFreeSpaceForHistoryArchives
}
torrent.DownloadAll()
m.publish(&Subscription{