Skip to content

Commit

Permalink
🎨 Support local file system sync & backup #11
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 31, 2024
1 parent 7fb6f6f commit c81535c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cloud/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"

"github.com/88250/gulu"
"github.com/shirou/gopsutil/v4/disk"
"github.com/siyuan-note/dejavu/entity"
"github.com/siyuan-note/dejavu/util"
"github.com/siyuan-note/logging"
)

Expand Down Expand Up @@ -300,11 +300,7 @@ func (local *Local) GetConf() *Conf {
}

func (local *Local) GetAvailableSize() int64 {
usage, err := disk.Usage(local.Local.Endpoint)
if err != nil {
return math.MaxInt64
}
return int64(usage.Free)
return util.GetFreeDiskSpace(local.Local.Endpoint)
}

func (local *Local) AddTraffic(*Traffic) {
Expand Down
33 changes: 33 additions & 0 deletions util/disk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// DejaVu - Data snapshot and sync.
// Copyright (c) 2022-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//go:build !ios && !android

package util

import (
"math"

"github.com/shirou/gopsutil/v4/disk"
)

func GetFreeDiskSpace(p string) (free int64) {
usage, err := disk.Usage(p)
if err != nil {
return math.MaxInt64
}
return int64(usage.Free)
}
23 changes: 23 additions & 0 deletions util/disk_mobile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// DejaVu - Data snapshot and sync.
// Copyright (c) 2022-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//go:build ios || android

package util

func GetFreeDiskSpace(p string) (free int64) {
return math.MaxInt64
}

0 comments on commit c81535c

Please sign in to comment.