mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-13 03:08:49 +00:00
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:
parent
58224826d2
commit
6e80ff28b4
2
Makefile
2
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
|
.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)
|
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
||||||
|
|||||||
@ -1071,13 +1071,25 @@ func cloneAndBuild() {
|
|||||||
// Remove existing repository if it exists (always start fresh)
|
// Remove existing repository if it exists (always start fresh)
|
||||||
if _, err := os.Stat("/home/debros/src"); err == nil {
|
if _, err := os.Stat("/home/debros/src"); err == nil {
|
||||||
fmt.Printf(" Removing existing repository...\n")
|
fmt.Printf(" Removing existing repository...\n")
|
||||||
// Remove as root since we're running as root
|
// Remove as debros user to avoid permission issues
|
||||||
if err := os.RemoveAll("/home/debros/src"); err != nil {
|
removeCmd := exec.Command("sudo", "-u", "debros", "rm", "-rf", "/home/debros/src")
|
||||||
fmt.Fprintf(os.Stderr, "⚠️ Failed to remove existing repo: %v\n", err)
|
if output, err := removeCmd.CombinedOutput(); err != nil {
|
||||||
// Try to continue anyway
|
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
|
// Clone fresh repository
|
||||||
fmt.Printf(" Cloning repository...\n")
|
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")
|
cmd := exec.Command("sudo", "-u", "debros", "git", "clone", "--branch", branch, "--depth", "1", "https://github.com/DeBrosOfficial/network.git", "/home/debros/src")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user