about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-05-05 17:02:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-05-05 17:02:46 -0700
commit5d5116e3343b5f6efa289e35e1c29b761db12068 (patch)
tree9c6c44aaea2731132ab51d6e0df0d7e3be589c13
parenta2f5a5d3fd13fba97571c39951304a44e7f84e5d (diff)
downloadmu-5d5116e3343b5f6efa289e35e1c29b761db12068.tar.gz
2928 - fix sandbox restore in edit/ and sandbox/
This had been broken ever since 2854, because we can't write tests for
restore-snapshots at the moment.
-rw-r--r--edit/005-sandbox.mu10
-rw-r--r--sandbox/005-sandbox.mu10
2 files changed, 14 insertions, 6 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 4d4b93ef..80dd4120 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -325,6 +325,7 @@ def restore-sandboxes env:address:programming-environment-data -> env:address:pr
     filename:address:array:character <- to-text idx
     contents:address:array:character <- restore filename
     break-unless contents  # stop at first error; assuming file didn't exist
+                           # todo: handle empty sandbox
     # create new sandbox for file
     curr <- new sandbox-data:type
     *curr <- put *curr, data:offset, contents
@@ -336,15 +337,18 @@ def restore-sandboxes env:address:programming-environment-data -> env:address:pr
       <end-restore-sandbox>
     }
     +continue
-    idx <- add idx, 1
     {
-      break-unless prev
+      break-if idx
+      *env <- put *env, sandbox:offset, curr
+    }
+    {
+      break-unless idx
       *prev <- put *prev, next-sandbox:offset, curr
     }
+    idx <- add idx, 1
     prev <- copy curr
     loop
   }
-  *env <- put *env, sandbox:offset, curr
   # update sandbox count
   *env <- put *env, number-of-sandboxes:offset, idx
 ]
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index c946fba2..227a1ee0 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -317,6 +317,7 @@ def! restore-sandboxes env:address:programming-environment-data -> env:address:p
     filename:address:array:character <- to-text idx
     contents:address:array:character <- restore filename
     break-unless contents  # stop at first error; assuming file didn't exist
+                           # todo: handle empty sandbox
     # create new sandbox for file
     curr <- new sandbox-data:type
     *curr <- put *curr, data:offset, contents
@@ -328,15 +329,18 @@ def! restore-sandboxes env:address:programming-environment-data -> env:address:p
       <end-restore-sandbox>
     }
     +continue
-    idx <- add idx, 1
     {
-      break-unless prev
+      break-if idx
+      *env <- put *env, sandbox:offset, curr
+    }
+    {
+      break-unless idx
       *prev <- put *prev, next-sandbox:offset, curr
     }
+    idx <- add idx, 1
     prev <- copy curr
     loop
   }
-  *env <- put *env, sandbox:offset, curr
   # update sandbox count
   *env <- put *env, number-of-sandboxes:offset, idx
 ]