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.
This commit is contained in:
anonpenguin23 2025-10-31 20:04:17 +02:00
parent 58224826d2
commit 6e80ff28b4
2 changed files with 17 additions and 5 deletions

View File

@ -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)'

View File

@ -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")