From 3d435275b26aa869e5baaa20524baba9592fe472 Mon Sep 17 00:00:00 2001
From: LaplongeJunior <laplongejunior@gmail.com>
Date: Sat, 1 Aug 2020 17:03:31 +0000
Subject: [PATCH] Added rollback of internal state in case of error

---
 scripts/libs/vshell.inc.src | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/scripts/libs/vshell.inc.src b/scripts/libs/vshell.inc.src
index 0f54f8a..e4dba7e 100644
--- a/scripts/libs/vshell.inc.src
+++ b/scripts/libs/vshell.inc.src
@@ -1,3 +1,7 @@
+// Untested!  
+// This file has only been merged into master because it depended into the Repo Unification Process
+// Which caused a lot of merge conflicts, so reducing merge requests made life easier for everybody at the time
+
 "#import libs/utils.inc.src"
 "#import libs/file.inc.src"
 
@@ -18,6 +22,7 @@ imports.vshell.constrs.shell = function(object)
             cmd = imports.utils.SafeMapAccess(imports.vshell.cmds,command[0])
             if cmd == null then 
                 print(cmd+ " is not a recognized command")
+                return
             end if
             
             // Remove the command name
@@ -26,8 +31,16 @@ imports.vshell.constrs.shell = function(object)
                 params.push(command[i])
             end for
             
+            heart = result.heart
+            current_path = result.current_path
+            
             result = cmd(self, params)
-            if result and typeof(result) != "function" then print(command[0] +" error: "+result)
+            if result and typeof(result) != "function" then
+                print(command[0] +" error: "+result)
+                // Rollback
+                result.heart = heart
+                result.current_path = current_path
+            end if
         end while
     end function
     
@@ -47,8 +60,17 @@ imports.vshell.constrs.shell = function(object)
             result = self.heart.File(path)
         end if
             
-        self.current_path = imports.file.GetDir(result.path)
+        if not imports.file.FileAccess(result,"r") then
+            print("Error, unable to access the file")
+            return
+        end if
+        folder = imports.file.GetDirRef(result)
+        if not imports.file.FileAccess(folder,"r") then
+            print("Error, unable to access the parent folder")
+            return
+        end if
         
+        self.current_path = folder.path
         if typeof(self.heart) == "file" then self.heart = result
         return result
     end function
@@ -111,4 +133,7 @@ imports.vshell.cmds.read = function(shell, params)
 end function
 
 imports.vshell.cmds.get = function(shell, params)
+end function
+
+imports.vshell.cmds.delete = function(shell, params)
 end function
\ No newline at end of file
-- 
GitLab