From 6e80ff28b43d4744a566dfbd51cae11bafb5b618 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Fri, 31 Oct 2025 20:04:17 +0200 Subject: [PATCH] refactor: improve repository removal and directory setup in cloneAndBuild function - Changed the repository removal process to use the 'debros' user to avoid permission issues, with a fallback to root if necessary. - Added a delay to ensure filesystem sync after removing the repository. - Ensured the parent directory exists and has the correct permissions, including setting ownership to the 'debros' user. --- Makefile | 2 +- pkg/cli/setup.go | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4283d21..90910d5 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test-e2e: .PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports -VERSION := 0.53.10 +VERSION := 0.53.11 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' diff --git a/pkg/cli/setup.go b/pkg/cli/setup.go index 7456a0f..60f7fd8 100644 --- a/pkg/cli/setup.go +++ b/pkg/cli/setup.go @@ -1071,13 +1071,25 @@ func cloneAndBuild() { // Remove existing repository if it exists (always start fresh) if _, err := os.Stat("/home/debros/src"); err == nil { fmt.Printf(" Removing existing repository...\n") - // Remove as root since we're running as root - if err := os.RemoveAll("/home/debros/src"); err != nil { - fmt.Fprintf(os.Stderr, "⚠️ Failed to remove existing repo: %v\n", err) - // Try to continue anyway + // Remove as debros user to avoid permission issues + removeCmd := exec.Command("sudo", "-u", "debros", "rm", "-rf", "/home/debros/src") + if output, err := removeCmd.CombinedOutput(); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to remove existing repo as debros user: %v\n%s\n", err, output) + // Try as root as fallback + if err := os.RemoveAll("/home/debros/src"); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to remove existing repo as root: %v\n", err) + } } + // Wait a moment to ensure filesystem syncs + time.Sleep(100 * time.Millisecond) } + // Ensure parent directory exists and has correct permissions + if err := os.MkdirAll("/home/debros", 0755); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to ensure debros home directory exists: %v\n", err) + } + exec.Command("chown", "debros:debros", "/home/debros").Run() + // Clone fresh repository fmt.Printf(" Cloning repository...\n") cmd := exec.Command("sudo", "-u", "debros", "git", "clone", "--branch", branch, "--depth", "1", "https://github.com/DeBrosOfficial/network.git", "/home/debros/src")