mirror of
https://github.com/rclone/rclone.git
synced 2025-08-10 06:09:44 +02:00
about: fix potential overflow of about in various backends
Before this fix it was possible for an about call in various backends to exceed an int64 and wrap. This patch causes it to clip to the max int64 value instead.
This commit is contained in:
@@ -1446,9 +1446,9 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
|
||||
}
|
||||
}
|
||||
usage = &fs.Usage{
|
||||
Total: fs.NewUsageValue(int64(total)), // quota of bytes that can be used
|
||||
Used: fs.NewUsageValue(int64(used)), // bytes in use
|
||||
Free: fs.NewUsageValue(int64(total - used)), // bytes which can be uploaded before reaching the quota
|
||||
Total: fs.NewUsageValue(total), // quota of bytes that can be used
|
||||
Used: fs.NewUsageValue(used), // bytes in use
|
||||
Free: fs.NewUsageValue(total - used), // bytes which can be uploaded before reaching the quota
|
||||
}
|
||||
return usage, nil
|
||||
}
|
||||
|
@@ -371,9 +371,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &fs.Usage{
|
||||
Total: fs.NewUsageValue(int64(info.Capacity)),
|
||||
Used: fs.NewUsageValue(int64(info.Used)),
|
||||
Free: fs.NewUsageValue(int64(info.Remaining)),
|
||||
Total: fs.NewUsageValue(info.Capacity),
|
||||
Used: fs.NewUsageValue(info.Used),
|
||||
Free: fs.NewUsageValue(info.Remaining),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -946,9 +946,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
||||
return nil, fmt.Errorf("failed to get Mega Quota: %w", err)
|
||||
}
|
||||
usage := &fs.Usage{
|
||||
Total: fs.NewUsageValue(int64(q.Mstrg)), // quota of bytes that can be used
|
||||
Used: fs.NewUsageValue(int64(q.Cstrg)), // bytes in use
|
||||
Free: fs.NewUsageValue(int64(q.Mstrg - q.Cstrg)), // bytes which can be uploaded before reaching the quota
|
||||
Total: fs.NewUsageValue(q.Mstrg), // quota of bytes that can be used
|
||||
Used: fs.NewUsageValue(q.Cstrg), // bytes in use
|
||||
Free: fs.NewUsageValue(q.Mstrg - q.Cstrg), // bytes which can be uploaded before reaching the quota
|
||||
}
|
||||
return usage, nil
|
||||
}
|
||||
|
@@ -793,7 +793,7 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
|
||||
return nil, err
|
||||
}
|
||||
usage = &fs.Usage{
|
||||
Used: fs.NewUsageValue(int64(info.SpaceUsed)),
|
||||
Used: fs.NewUsageValue(info.SpaceUsed),
|
||||
}
|
||||
return usage, nil
|
||||
}
|
||||
|
@@ -1863,9 +1863,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
||||
free := vfsStats.FreeSpace()
|
||||
used := total - free
|
||||
return &fs.Usage{
|
||||
Total: fs.NewUsageValue(int64(total)),
|
||||
Used: fs.NewUsageValue(int64(used)),
|
||||
Free: fs.NewUsageValue(int64(free)),
|
||||
Total: fs.NewUsageValue(total),
|
||||
Used: fs.NewUsageValue(used),
|
||||
Free: fs.NewUsageValue(free),
|
||||
}, nil
|
||||
} else if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
|
@@ -494,11 +494,11 @@ func (f *Fs) About(ctx context.Context) (_ *fs.Usage, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bs := int64(stat.BlockSize())
|
||||
bs := stat.BlockSize()
|
||||
usage := &fs.Usage{
|
||||
Total: fs.NewUsageValue(bs * int64(stat.TotalBlockCount())),
|
||||
Used: fs.NewUsageValue(bs * int64(stat.TotalBlockCount()-stat.FreeBlockCount())),
|
||||
Free: fs.NewUsageValue(bs * int64(stat.AvailableBlockCount())),
|
||||
Total: fs.NewUsageValue(bs * stat.TotalBlockCount()),
|
||||
Used: fs.NewUsageValue(bs * (stat.TotalBlockCount() - stat.FreeBlockCount())),
|
||||
Free: fs.NewUsageValue(bs * stat.AvailableBlockCount()),
|
||||
}
|
||||
return usage, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user