Skip to content

Commit c323792

Browse files
authored
Merge pull request #8 from MinuteZero/fix-stat-cross-platform
Fix: make stat cross-platform compatible (macOS/Linux)
2 parents 22b14d2 + 30e5b1e commit c323792

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

utils/docker/start-codebuff.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ cleanup() {
3535
}
3636
trap cleanup SIGINT SIGTERM EXIT
3737

38+
# Determine correct 'stat' syntax based on platform (BSD/macOS vs GNU/Linux)
39+
if stat -c %Y / >/dev/null 2>&1; then
40+
# GNU stat (Linux)
41+
STAT_CMD="stat -c"
42+
else
43+
# BSD stat (macOS, FreeBSD, etc.)
44+
STAT_CMD="stat -f"
45+
fi
46+
3847
# Get the directory where this script is located
3948
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4049

@@ -51,10 +60,10 @@ if ! docker images codebuff --format "{{.ID}}" | grep -q .; then
5160
docker build -t codebuff "$SCRIPT_DIR" || { error "Failed to build Docker image"; exit 1; }
5261
else
5362
# Always rebuild if any of the scripts have been modified
54-
DOCKERFILE_MTIME=$(stat -f %m "$SCRIPT_DIR/Dockerfile")
55-
WRAPPER_MTIME=$(stat -f %m "$SCRIPT_DIR/codebuff-wrapper.sh")
56-
ENTRYPOINT_MTIME=$(stat -f %m "$SCRIPT_DIR/entrypoint.sh")
57-
BRIDGE_MTIME=$(stat -f %m "$SCRIPT_DIR/message-bridge.sh")
63+
DOCKERFILE_MTIME=$($STAT_CMD %m "$SCRIPT_DIR/Dockerfile")
64+
WRAPPER_MTIME=$($STAT_CMD %m "$SCRIPT_DIR/codebuff-wrapper.sh")
65+
ENTRYPOINT_MTIME=$($STAT_CMD %m "$SCRIPT_DIR/entrypoint.sh")
66+
BRIDGE_MTIME=$($STAT_CMD %m "$SCRIPT_DIR/message-bridge.sh")
5867

5968
# Get the most recent modification time
6069
LATEST_MTIME=$DOCKERFILE_MTIME
@@ -65,7 +74,7 @@ else
6574
done
6675

6776
debug "Latest modification time: $LATEST_MTIME"
68-
debug "Raw modification time: $(stat -f %Sm "$SCRIPT_DIR/Dockerfile")"
77+
debug "Raw modification time: $($STAT_CMD %Sm "$SCRIPT_DIR/Dockerfile")"
6978

7079
# Always rebuild for now - safer while we're actively developing
7180
log "Scripts may have been modified. Rebuilding image..."

0 commit comments

Comments
 (0)