diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b1b7f98 --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "clipse dev shell"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + go + gnumake + ]; + + shellHook = '' + echo "clipse dev shell ready" + echo " make wayland → Wayland build" + echo " make x11 → X11 build" + ''; + }; + }; +} diff --git a/handlers/common.go b/handlers/common.go index 2492908..0fc6ccf 100644 --- a/handlers/common.go +++ b/handlers/common.go @@ -13,7 +13,7 @@ import ( ) func SaveImage(imgData []byte) error { - if !utils.DiskspaceAvailable(len(imgData)) { + if !utils.DiskspaceAvailable(len(imgData), config.ClipseConfig.TempDirPath) { return fmt.Errorf("no available disk space to store image") } @@ -33,6 +33,9 @@ func SaveImage(imgData []byte) error { } func SaveText(textData string) error { + if !utils.DiskspaceAvailable(len(textData), config.ClipseConfig.HistoryFilePath) { + return fmt.Errorf("no available disk space to store text") + } if err := config.AddClipboardItem(textData, "null"); err != nil { return err } diff --git a/handlers/wayland.go b/handlers/wayland.go index 8e14255..9692c53 100644 --- a/handlers/wayland.go +++ b/handlers/wayland.go @@ -56,6 +56,10 @@ func StoreWLData() { if inputStr == "" { return } + if !utils.DiskspaceAvailable(len(inputStr), config.ClipseConfig.HistoryFilePath) { + utils.LogERROR("no available disk space to store text") + return + } if err := config.AddClipboardItem(inputStr, "null"); err != nil { utils.LogERROR(fmt.Sprintf("failed to add new item `( %s )` | %s", input, err)) } diff --git a/utils/disk.go b/utils/disk.go index 4360b85..cbab45a 100644 --- a/utils/disk.go +++ b/utils/disk.go @@ -6,14 +6,19 @@ import ( "golang.org/x/sys/unix" ) -func DiskspaceAvailable(bytes int) bool { +// path ex. config.ClipseConfig.HistoryFilePath, config.ClipseConfig.TempDirPath, defaults to "/" +func DiskspaceAvailable(bytes int, path ...string) bool { + checkPath := "/" + if len(path) > 0 { + checkPath = path[0] + } + var stat unix.Statfs_t - if err := unix.Statfs("/", &stat); err != nil { + if err := unix.Statfs(checkPath, &stat); err != nil { LogERROR(fmt.Sprintf("failed to check disk space: %s", err)) return true } - - bytefree := (stat.Bavail * uint64(stat.Bsize)) + bytefree := stat.Bavail * uint64(stat.Bsize) return bytefree > (uint64(bytes) * 2) // *2 for safety buffer }