From b1a4614b35f9c892e5bf08fc0792283ba360d493 Mon Sep 17 00:00:00 2001
From: Lucendio <dev@lucend.io>
Date: Wed, 5 May 2021 22:15:08 +0200
Subject: [PATCH] Add a confirmation failsafe before deleting files

The function `dir`, used to determine MKFILE_DIR can take multiple
parameters. As a result, if this repository is located in a path
that contains a white space, the result of `abspath` is interpreted
as multiple parameters, because Make uses white spaces as separator
or delimiter. Quoting does not help. Spaces as such only work in
shell commands within target bodies.

So, the chosen workaround is to add a failsafe to ask the user for
confirmation to give them a chance to double check what is actually
being deleted.

* added a warning at the top of the readme to raise awareness
---
 Makefile  | 8 ++++++--
 README.md | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 3154eea..04568cd 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,9 @@ $(LOCAL_DIR)/%/:
 
 .PHONY: clean
 clean:
-	rm -rf \
+	echo "DELETING: $(APP_NODE_MODULE_DIRS) $(TEMP_DIR) $(LOCAL_DIR)/dist" | tr ' ' '\n'
+	read -p "OK? [N,y] " input; [[ "$${input}" == "y" ]] \
+	&& rm -rf \
 		$(APP_NODE_MODULE_DIRS) \
 		$(TEMP_DIR) \
 		$(LOCAL_DIR)/dist
@@ -43,7 +45,9 @@ clean:
 build: SERVER_PUBLIC_URL ?= http://127.0.0.1:3001
 build: APP_BUILD_PATH ?= $(TEMP_DIR)
 build:
-	rm -rf $(APP_BUILD_PATH)
+	echo "DELETING: $(APP_BUILD_PATH)" | tr ' ' '\n'
+	read -p "OK? [N,y] " input; [[ "$${input}" == "y" ]] \
+	&& rm -rf $(APP_BUILD_PATH)
 
 	cp -r $(MKFILE_DIR)/app/server/src $(APP_BUILD_PATH)
 	cp $(MKFILE_DIR)/app/server/package* $(APP_BUILD_PATH)/
diff --git a/README.md b/README.md
index d94d924..ea65e7d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
 Lecture: DevOps - Application
 =============================
 
+> :warning: __Invoking `make` in a path containing white spaces may lead to unforeseen side effects like DATA LOSS !__
+
 
 This repository contains the [application](./app/README.md) that is supposed be used as *deployable workload* in the
 [project assignment](https://github.com/lucendio/lecture-devops-material/blob/master/assignments/project-work.md)
-- 
GitLab