forked from AlloyTools/org.alloytools.alloy
-
Notifications
You must be signed in to change notification settings - Fork 9
Trash
Nuno Macedo edited this page Apr 22, 2021
·
6 revisions
The goal of this challenge is to design a simple file trash, such that a deleted file can still be restored if the trash is not emptied.
Consider the following partial model of this design in Electrum:
var sig File {}
var sig Trash in File {}
// delete a file
pred delete[f : File] {
f not in Trash
Trash' = Trash + f
File' = File
}
// restore a file
pred restore[f : File] { ... }
// empty the trash
pred empty { ... }
// do nothing
pred do_nothing {
Trash' = Trash
File' = File
}
fact behavior {
// initial state
no Trash
// transitions
always (
(some f: File | delete[f] or restore[f]) or empty or do_nothing
)
}
assert restoreAfterDelete {
// Every restored file was once deleted
always (all f : File | restore[f] implies once delete[f])
}
check restoreAfterDelete for 10 steps
assert deleteAll {
// If the trash contains all files and is emptied
// then no files will ever exist afterwards
always ((File in Trash and empty) implies after always no File)
}
check deleteAll
pred restoreEnabled[f : File] {
// a file can be restored if it is in the trash
f in Trash
}
assert restoreIsPossibleBeforeEmpty {
// a deleted file can still be restored if the trash is not emptied
always (all f:File | delete[f] implies (empty releases restoreEnabled[f]))
}
check restoreIsPossibleBeforeEmpty
- Finish the model by defining the predicates
restore
andempty
- Using the simulator and an empty
run
command, show that the following scenarios are possible:- Starting with 3 files, delete all of them and empty the trash
- Starting with 1 file keep deleting and restoring it forever
- Specify and verify the following properties:
- The set of files never increases
- The set of files only changes when empty is performed
- If files are never deleted the trash can never be emptied
- Restoring a file immediately after deleting it undos the operation
- Fix the specification of assertion
restoreIsPossibleBeforeEmpty
- Assume the existence of protected files
- Adapt the model so that this kind of files is supported
- Adapt the operations accordingly
- Use the simulator to show that if all files are protected, no deletions may occur
- Specify and verify that, if there are protected files, some file will always exist