Summary#
A file written by path — receipts/{order.Id}.pdf — is just bytes at an address. Written with about: order, it is
also recorded against the order, so everything that later has to reach "every copy of this person's data" can:
File.About(row)— the paths written about the row;File.DeleteAbout(row)— deletes them, answering how many;- deleting the row, or restricting it (restricted rows and purpose reads (Restriction, [PurposeRead])), deletes its files after the commit.
Signature#
bool File.WriteAllBytes(string path, byte[] bytes, about: row)
bool File.WriteAllText(string path, string text, about: row)
List<string> File.About(row)
int File.DeleteAbout(row)Description#
Needs use Osysharp.Storage; (the register lives there). about: takes a stored row of any entity; writing the same
path about the same row twice records it once. A restricted row's renderings are deleted rather than kept: a purpose
read renders them again when the purpose needs them.
If a file cannot be deleted when its row goes, its register entry stays — so File.About and
Assert.NoTraceOf (Assert.NoTraceOf(token)) still find it, rather than the copy silently surviving.
Examples#
app Shop { use Osysharp.Storage; }
entity Order {
[Required, MaxLength(20)] string Number;
[MaxLength(200)] string? Buyer;
security { allow read, create, update, delete when IsAuthenticated || IsAnonymous; }
}
string WriteReceipt(Order o) {
var path = $"receipts/{o.Number}.txt";
File.WriteAllText(path, "Receipt for " + o.Buyer, about: o);
return path;
}[Test]
void A_receipt_goes_with_its_order() {
var o = new Order { Number = "O-1", Buyer = "Ann" };
UnitOfWork.Commit();
var path = WriteReceipt(o);
Assert.Equal(1, File.About(o).Count);
o.Delete();
UnitOfWork.Commit();
Assert.False(File.Exists(path));
}See also#
- Files (addressing something the app stores) — the two ways the platform stores a file
- restricted rows and purpose reads (Restriction, [PurposeRead]) — a restricted row takes its renderings with it
- Assert.NoTraceOf(token) — proving a person's data is gone, files included