From 8455937c1b6c962ba266b13895a2ea0ae44fe373 Mon Sep 17 00:00:00 2001 From: Dziksonn <40899061+Dziksonn@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:58:50 +0200 Subject: [PATCH 1/3] issue/348: (fix) ability to check actual storage path in DiskspaceAvailable --- utils/disk.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/utils/disk.go b/utils/disk.go index 4360b85..add01b0 100644 --- a/utils/disk.go +++ b/utils/disk.go @@ -6,14 +6,19 @@ import ( "golang.org/x/sys/unix" ) -func DiskspaceAvailable(bytes int) bool { - var stat unix.Statfs_t - if err := unix.Statfs("/", &stat); err != nil { - LogERROR(fmt.Sprintf("failed to check disk space: %s", err)) - return true - } +//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] + } - bytefree := (stat.Bavail * uint64(stat.Bsize)) + var stat unix.Statfs_t + 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) - return bytefree > (uint64(bytes) * 2) // *2 for safety buffer -} + return bytefree > (uint64(bytes) * 2) // *2 for safety buffer +} \ No newline at end of file From b136e8d36ec551401c826904a660c2aca1b32356 Mon Sep 17 00:00:00 2001 From: Dziksonn <40899061+Dziksonn@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:00:09 +0200 Subject: [PATCH 2/3] issue/348: (fix) add disk space checks before storing text (common and wayland) --- handlers/common.go | 5 ++++- handlers/wayland.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)) } From 7953820865fe87e09957716959ffcec300102a1e Mon Sep 17 00:00:00 2001 From: Dziksonn <40899061+Dziksonn@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:41:25 +0200 Subject: [PATCH 3/3] Issue/348: (fix)(lint) fix linting for disk.go --- flake.nix | 23 +++++++++++++++++++++++ utils/disk.go | 26 +++++++++++++------------- 2 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 flake.nix 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/utils/disk.go b/utils/disk.go index add01b0..cbab45a 100644 --- a/utils/disk.go +++ b/utils/disk.go @@ -6,19 +6,19 @@ import ( "golang.org/x/sys/unix" ) -//path ex. config.ClipseConfig.HistoryFilePath, config.ClipseConfig.TempDirPath, defaults to "/" +// 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] - } + checkPath := "/" + if len(path) > 0 { + checkPath = path[0] + } - var stat unix.Statfs_t - 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) + var stat unix.Statfs_t + 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) - return bytefree > (uint64(bytes) * 2) // *2 for safety buffer -} \ No newline at end of file + return bytefree > (uint64(bytes) * 2) // *2 for safety buffer +}