GITv

Make deleted repositories and overwritten history recoverable

Browse files

Deleting a repository, over SSH or as root, now moves it to <owner>/.trash/<name>.<unix time> instead of removing it. New admin commands list the trash, restore an entry (never over an existing repository), and purge entries older than 30 days; a daily systemd timer runs the purge. Pushes now run with reflogs on every ref and keep unreachable objects for 30 days, so a force-pushed branch can be recovered. Because git drops a deleted branch's reflog, each push also appends its ref changes to gitv-push.log in the repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 15:51
Commit
08ea36cf7f62
Parent
a87990a

5 files changed +368−21

+17−2
@@ -17,7 +17,19 @@ gitv visibility um9i my-project public
Anyone can now find it on the repository index, browse its files and history, and run `git clone https://git.um9i.dev/um9i/my-project`. Use the same visibility command with `private` to require sign-in again and disable HTTPS fetches. Copies already downloaded remain with their recipients. Pushes use SSH.
**Storage.** Repositories live in `/srv/gitv/repos/<owner>/<name>.git`. Owner and repository directories must be real directories: GITv refuses symlinks at either level rather than follow them out of the tree. Everything works through open directory handles: git runs inside the repository directory it opened, new repositories are built and published inside the open owner directory (never replacing anything already at the name), deletion removes through handles without following links, and the web index lists and fingerprints repositories the same way. A path swapped for a symlink after a check can't redirect any of it.
**Storage.** Repositories live in `/srv/gitv/repos/<owner>/<name>.git`. Owner and repository directories must be real directories: GITv refuses symlinks at either level rather than follow them out of the tree. Everything works through open directory handles: git runs inside the repository directory it opened, new repositories are built and published inside the open owner directory (never replacing anything already at the name), deletion and purging move and remove through handles without following links, and the web index lists and fingerprints repositories the same way. A path swapped for a symlink after a check can't redirect any of it.
**Deleting and recovering.** `delete` (over SSH or as root) never removes anything: it moves the repository to `<owner>/.trash/<name>.<unix time>`, where it stops being served. The operator manages the trash:
```sh
gitv trash # what's waiting, and for how long
gitv restore um9i my-project.1763800000 # back under its old name (or --as other-name)
gitv purge # remove entries deleted 30+ days ago (--older-than-days N)
```
`deploy/gitv-purge.timer` runs `gitv purge` daily, so deleted repositories can be restored for 30 days.
History overwritten by a push can be recovered for the same 30 days. Every push records a reflog entry for each ref it changes, and keeps unreachable objects as long as those entries; for example, `git -C <repo> rev-parse main@{1}` finds where `main` pointed before a force-push. Git drops a branch's reflog when the branch is deleted, so each push also appends its ref changes to `gitv-push.log` in the repository (`<unix time> <old> <new> <ref>`, `-` for none). To bring back a deleted branch, find its last commit there and run `git -C <repo> branch <name> <commit>`.
The browser follows the system's light or dark setting. Its stylesheet (`assets/style.css`) and the Red Hat Display, Text and Mono fonts (`assets/fonts`, SIL Open Font License) are built into the `gitv-web` binary, so the server needs no font packages.
@@ -75,4 +87,7 @@ The deployment files are the source copies for the Fedora host. Caddy uses
`deploy/Caddyfile` at `/etc/caddy/Caddyfile`. The web service runs with
`deploy/gitv-web.service` at `/etc/systemd/system/gitv-web.service`, alongside
Fedora's distribution-provided systemd defaults. OpenSSH uses
`deploy/sshd-gitv.conf` at `/etc/ssh/sshd_config.d/90-gitv.conf`.
`deploy/sshd-gitv.conf` at `/etc/ssh/sshd_config.d/90-gitv.conf`. The trash purge runs from
`deploy/gitv-purge.service` and `deploy/gitv-purge.timer` in `/etc/systemd/system`, enabled with
`systemctl enable --now gitv-purge.timer`.
@@ -0,0 +1,18 @@
[Unit]
Description=Remove GITv repositories deleted more than 30 days ago
[Service]
Type=oneshot
ExecStart=/usr/local/bin/gitv purge
NoNewPrivileges=yes
ProtectSystem=strict
ReadWritePaths=/srv/gitv/repos
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
PrivateNetwork=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictSUIDSGID=yes
CapabilityBoundingSet=CAP_DAC_OVERRIDE
@@ -0,0 +1,10 @@
[Unit]
Description=Daily purge of GITv's repository trash
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
@@ -1,5 +1,6 @@
//! Private Git hosting over OpenSSH and Git's native pack protocol.
use std::collections::BTreeMap;
use std::fs;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
@@ -13,7 +14,7 @@ use gitv::{
open_owner, open_root, remove_tree_at, repo_dir, repo_in, repos_root, valid_name,
};
use nix::errno::Errno;
use nix::fcntl::{Flock, FlockArg, RenameFlags, renameat, renameat2};
use nix::fcntl::{Flock, FlockArg, OFlag, RenameFlags, openat, renameat2};
use nix::sys::stat::{Mode, fchmod, fstat, mkdirat};
use nix::unistd::{Gid, Uid, UnlinkatFlags, fchown, geteuid, unlinkat};
use std::ffi::OsStr;
@@ -25,7 +26,7 @@ const HELP: &str = "Commands for your key, run as: ssh git@git.um9i.dev <command
list list your repositories
create <name> create an empty repository
visibility <name> public|private set web access
delete <name> --yes delete a repository permanently
delete <name> --yes move a repository to the trash (the operator can restore it for 30 days)
Pushing to a repository that does not exist yet creates it.";
#[derive(Parser)]
@@ -46,16 +47,33 @@ enum Action {
},
/// Set repository web visibility to public or private (root)
Visibility { owner: String, name: String, visibility: String },
/// Delete a repository permanently (root)
/// Move a repository to its owner's trash (root)
Delete {
#[arg(value_parser = name)]
owner: String,
#[arg(value_parser = name)]
name: String,
/// Confirm permanent deletion
/// Confirm deletion
#[arg(long)]
yes: bool,
},
/// List deleted repositories waiting in the trash (root)
Trash,
/// Put a deleted repository back, under its old name or another (root)
Restore {
#[arg(value_parser = name)]
owner: String,
/// The trash entry, as `gitv trash` lists it: <name>.<deletion time>
entry: String,
/// Restore under this name instead
#[arg(long = "as", value_parser = name)]
as_name: Option<String>,
},
/// Permanently remove trash entries deleted at least this many days ago (root)
Purge {
#[arg(long, default_value_t = TRASH_DAYS)]
older_than_days: u64,
},
/// Register an Ed25519 public key for an owner (root)
AddKey {
#[arg(value_parser = name)]
@@ -270,20 +288,132 @@ fn build_and_publish(directory: &OwnedFd, staging: &OwnedFd, target: &str) -> Re
Ok(())
}
/// Delete `<owner>/<name>.git`. One handle on the owner directory serves the check, the rename
/// and the removal, which works through handles all the way down and never follows a symlink.
fn delete(owner: &str, name: &str) -> Result<(), String> {
/// Deleted repositories wait in `<owner>/.trash` for this many days before `gitv purge` removes them.
const TRASH_DAYS: u64 = 30;
/// The trash directory inside each owner's directory. Its leading dot keeps it out of every listing.
const TRASH: &str = ".trash";
fn unix_now() -> u64 {
SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |d| d.as_secs())
}
/// The owner's trash directory, created (private, and the git account's) if needed.
fn trash_directory(owner_dir: &OwnedFd) -> Result<OwnedFd, String> {
match mkdirat(owner_dir, TRASH, Mode::S_IRWXU) {
Ok(()) | Err(Errno::EEXIST) => {}
Err(e) => return Err(format!("cannot create the trash: {e}")),
}
let trash = open_dir_at(owner_dir, OsStr::new(TRASH)).map_err(|_| "the trash is not a directory".to_string())?;
if let Some((uid, gid)) = git_account()? {
fchown(&trash, Some(uid), Some(gid)).map_err(|e| e.to_string())?;
}
Ok(trash)
}
/// A trash entry's repository name and deletion time: `<name>.<unix seconds>`.
fn parse_trash_entry(entry: &str) -> Option<(&str, u64)> {
let (name, stamp) = entry.rsplit_once('.')?;
(valid_name(name) && !stamp.is_empty() && stamp.bytes().all(|b| b.is_ascii_digit()))
.then_some((name, stamp.parse().ok()?))
}
/// Move `<owner>/<name>.git` into the owner's trash, returning the trash entry's name. One handle
/// on the owner directory serves the check and the move; if the entry were swapped for a symlink
/// after the check, only the link would be moved. Nothing is removed until `gitv purge`.
fn delete(owner: &str, name: &str) -> Result<String, String> {
let directory = open_owner(owner).ok_or("repository unavailable")?;
repo_in(&directory, owner, name).ok_or("repository unavailable")?;
// A hidden name stops the repository serving at once, before the slow removal. If the
// entry were swapped for a symlink after the check, only the link would be moved and removed.
let staging = format!(".delete-{}-{name}", std::process::id());
renameat(&directory, format!("{name}.git").as_str(), &directory, staging.as_str()).map_err(|e| e.to_string())?;
remove_tree_at(&directory, OsStr::new(&staging)).map_err(|e| e.to_string())?;
println!("deleted {owner}/{name}.git");
let trash = trash_directory(&directory)?;
let entry = format!("{name}.{}", unix_now());
renameat2(&directory, format!("{name}.git").as_str(), &trash, entry.as_str(), RenameFlags::RENAME_NOREPLACE)
.map_err(|e| match e {
Errno::EEXIST => "the repository was deleted moments ago under the same name; try again".to_string(),
e => e.to_string(),
})?;
Ok(entry)
}
/// Every trash entry: owner, entry name, and deletion time when the name carries one.
fn trash_entries() -> Result<Vec<(String, String, Option<u64>)>, String> {
let root = open_root().ok_or("cannot open the repository root")?;
let mut found = Vec::new();
for owner in entries(&root).into_iter().filter_map(|o| o.into_string().ok()).filter(|o| valid_name(o)) {
let Some(owner_dir) = open_owner(&owner) else { continue };
let trash = match open_dir_at(&owner_dir, OsStr::new(TRASH)) {
Ok(trash) => trash,
Err(Errno::ENOENT) => continue,
Err(e) => return Err(format!("cannot open {owner}/{TRASH}: {e}")),
};
let names = gitv::try_entries(&trash).map_err(|e| format!("cannot list {owner}/{TRASH}: {e}"))?;
for entry in names {
let entry = entry.to_string_lossy().into_owned();
let stamp = parse_trash_entry(&entry).map(|(_, stamp)| stamp);
found.push((owner.clone(), entry, stamp));
}
}
found.sort();
Ok(found)
}
fn list_trash() -> Result<(), String> {
let now = unix_now();
for (owner, entry, stamp) in trash_entries()? {
match stamp {
Some(stamp) => {
let days = now.saturating_sub(stamp) / 86_400;
let left = TRASH_DAYS.saturating_sub(days);
println!("{owner} {entry} deleted {days} days ago, purged in {left} days");
}
None => println!("{owner} {entry} (not a trash entry; purge leaves it alone)"),
}
}
Ok(())
}
/// Move a trash entry back to `<owner>/<name>.git`, never replacing anything at that name.
fn restore(owner: &str, entry: &str, as_name: Option<&str>) -> Result<(), String> {
let (original, _) = parse_trash_entry(entry).ok_or("not a trash entry; see `gitv trash`")?;
let name = as_name.unwrap_or(original);
let directory = open_owner(owner).ok_or("no such owner")?;
let trash = open_dir_at(&directory, OsStr::new(TRASH)).map_err(|_| "this owner has no trash")?;
renameat2(&trash, entry, &directory, format!("{name}.git").as_str(), RenameFlags::RENAME_NOREPLACE).map_err(
|e| match e {
Errno::EEXIST => format!("{owner}/{name}.git already exists; restore with --as <other name>"),
Errno::ENOENT => "no such trash entry; see `gitv trash`".to_string(),
e => e.to_string(),
},
)?;
println!("restored git@{HOST}:{owner}/{name}.git");
Ok(())
}
/// Remove trash entries deleted at least `days` days ago, through handles and without following
/// symlinks. Entries that don't look like `<name>.<time>` are left for a person to look at.
fn purge(days: u64) -> Result<(), String> {
let cutoff = days.saturating_mul(86_400);
let now = unix_now();
let mut failures = 0;
for (owner, entry, stamp) in trash_entries()? {
let Some(stamp) = stamp else { continue };
if now.saturating_sub(stamp) < cutoff {
continue;
}
let removed = open_owner(&owner)
.ok_or_else(|| "owner directory unavailable".to_string())
.and_then(|dir| open_dir_at(&dir, OsStr::new(TRASH)).map_err(|e| e.to_string()))
.and_then(|trash| remove_tree_at(&trash, OsStr::new(&entry)).map_err(|e| e.to_string()));
match removed {
Ok(()) => println!("purged {owner}/{TRASH}/{entry}"),
Err(e) => {
failures += 1;
log_operator(&format!("purging {owner}/{TRASH}/{entry}: {e}"));
eprintln!("gitv: couldn't purge {owner}/{TRASH}/{entry}: {e}");
}
}
}
if failures == 0 { Ok(()) } else { Err(format!("{failures} trash entries couldn't be purged")) }
}
fn add_key(owner: &str, file: &Path) -> Result<(), String> {
let text = fs::read_to_string(file).map_err(|e| e.to_string())?;
let parts: Vec<&str> = text.split_whitespace().collect();
@@ -417,7 +547,13 @@ fn serve(owner: &str, command: &str) -> Result<u8, String> {
if rest != ["--yes"] {
return Err(format!("deleting {owner}/{name}.git is permanent; run: delete {name} --yes"));
}
delete(owner, name)?;
let entry = delete(owner, name)?;
log_operator(&format!(
"{owner}/{name}.git moved to the trash as {owner}/{TRASH}/{entry} by its owner's key"
));
println!(
"moved {owner}/{name}.git to the trash; the server's operator can restore it for {TRASH_DAYS} days"
);
}
_ => return Err("unknown command; run: ssh git@git.um9i.dev help".into()),
}
@@ -477,13 +613,96 @@ fn serve_git(owner: &str, program: &str, path: &str) -> Result<u8, String> {
{
command.env("GIT_PROTOCOL", protocol);
}
let pushing = program == "git-receive-pack";
let before = if pushing {
// Every ref update gets a reflog entry (bare repositories keep none by default), and
// objects nothing refers to any more stay as long as those entries do. Given through
// the environment, so it covers every repository, old or new, and the gc a push
// triggers inherits it.
command.envs(RECOVERY_CONFIG.iter().enumerate().flat_map(|(i, (key, value))| {
[(format!("GIT_CONFIG_KEY_{i}"), *key), (format!("GIT_CONFIG_VALUE_{i}"), *value)]
}));
command.env("GIT_CONFIG_COUNT", RECOVERY_CONFIG.len().to_string());
ref_snapshot(&repo)
.inspect_err(|e| log_operator(&format!("{owner}/{name}.git: no push log for this push: {e}")))
.ok()
} else {
None
};
let status = command.stdin(Stdio::inherit()).stdout(Stdio::inherit()).status().map_err(|e| e.to_string())?;
if program == "git-receive-pack" && status.success() {
if let Some(before) = before
&& let Err(e) = ref_snapshot(&repo).and_then(|after| record_push(&repo, &before, &after))
{
log_operator(&format!("{owner}/{name}.git: couldn't write the push log: {e}"));
}
if pushing && status.success() {
fix_head(&repo)?;
}
Ok(status.code().unwrap_or(1) as u8)
}
/// Configuration every push runs with, so overwritten or deleted history can be recovered for
/// [`TRASH_DAYS`]: reflogs on every ref, and unreachable objects kept as long as their entries.
const RECOVERY_CONFIG: [(&str, &str); 3] = [
("core.logAllRefUpdates", "always"),
("gc.reflogExpireUnreachable", "30.days.ago"),
("gc.pruneExpire", "30.days.ago"),
];
/// Where each repository records its pushes' ref changes. Git drops a branch's reflog when the
/// branch is deleted; this keeps the commit it pointed at findable.
const PUSH_LOG: &str = "gitv-push.log";
/// Every ref and the object it names.
fn ref_snapshot(repo: &RepoDir) -> Result<BTreeMap<Vec<u8>, Vec<u8>>, String> {
let out = git(repo, &["for-each-ref", "--format=%(objectname) %(refname)"])?;
// A ref name can't contain a space or a newline.
Ok(out
.split(|b| *b == b'\n')
.filter_map(|line| {
let space = line.iter().position(|b| *b == b' ')?;
Some((line[space + 1..].to_vec(), line[..space].to_vec()))
})
.collect())
}
/// Append one line per changed ref to [`PUSH_LOG`]: `<unix time> <old> <new> <ref>`, with `-`
/// for a ref that didn't exist before or doesn't after. Two pushes landing at once may share
/// their lines between them, but every change before and after is recorded.
fn record_push(
repo: &RepoDir,
before: &BTreeMap<Vec<u8>, Vec<u8>>,
after: &BTreeMap<Vec<u8>, Vec<u8>>,
) -> Result<(), String> {
let now = unix_now().to_string();
let mut lines = Vec::new();
let mut line = |old: &[u8], new: &[u8], name: &[u8]| {
lines.extend_from_slice(now.as_bytes());
for field in [old, new, name] {
lines.push(b' ');
lines.extend_from_slice(field);
}
lines.push(b'\n');
};
for (name, old) in before {
match after.get(name) {
Some(new) if new == old => {}
Some(new) => line(old, new, name),
None => line(old, b"-", name),
}
}
for (name, new) in after.iter().filter(|(name, _)| !before.contains_key(*name)) {
line(b"-", new, name);
}
if lines.is_empty() {
return Ok(());
}
let flags = OFlag::O_WRONLY | OFlag::O_APPEND | OFlag::O_CREAT | OFlag::O_NOFOLLOW | OFlag::O_CLOEXEC;
let fd = openat(repo.handle(), PUSH_LOG, flags, Mode::from_bits_truncate(0o640)).map_err(|e| e.to_string())?;
// One write, so lines from simultaneous pushes don't interleave mid-line.
fs::File::from(fd).write_all(&lines).map_err(|e| e.to_string())
}
/// Point HEAD at a pushed branch when its current target does not exist. Branch names are
/// bytes (one per line; a ref can't contain a newline), so names with spaces, non-breaking
/// spaces or non-UTF-8 bytes are passed to git exactly as they are.
@@ -530,8 +749,12 @@ fn run() -> Result<u8, String> {
if !yes {
return Err(format!("deleting {owner}/{name}.git is permanent; pass --yes to confirm"));
}
delete(&owner, &name)?;
let entry = delete(&owner, &name)?;
println!("moved {owner}/{name}.git to {owner}/{TRASH}/{entry}; restore with: gitv restore {owner} {entry}");
}
Action::Trash => list_trash()?,
Action::Restore { owner, entry, as_name } => restore(&owner, &entry, as_name.as_deref())?,
Action::Purge { older_than_days } => purge(older_than_days)?,
Action::Visibility { owner, name, visibility: value } => visibility(&owner, &name, &value)?,
Action::AddKey { owner, public_key } => add_key(&owner, &public_key)?,
Action::Serve { .. } => unreachable!(),
@@ -55,9 +55,23 @@ fn create_list_and_delete() {
assert!(stderr(&out).contains("delete notes --yes"), "{}", stderr(&out));
assert!(host.repo("ada", "notes").exists(), "nothing is deleted without --yes");
assert!(host.ssh("ada", "delete notes --yes").status.success());
let out = host.ssh("ada", "delete notes --yes");
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("trash"), "{}", stdout(&out));
assert!(!host.repo("ada", "notes").exists());
assert_eq!(trash(&host, "ada").len(), 1, "the repository waits in the trash");
assert!(host.logged().contains("ada/notes.git moved to the trash"), "{}", host.logged());
assert!(!host.ssh("ada", "delete notes --yes").status.success(), "a missing repository can't be deleted");
assert_eq!(stdout(&host.ssh("ada", "list")), "git@git.um9i.dev:ada/alpha.git\n", "the trash isn't listed");
}
/// The names in an owner's trash.
fn trash(host: &Host, owner: &str) -> Vec<String> {
let mut names: Vec<String> = fs::read_dir(host.repos.join(owner).join(".trash"))
.map(|dir| dir.map(|e| e.unwrap().file_name().into_string().unwrap()).collect())
.unwrap_or_default();
names.sort();
names
}
#[test]
@@ -153,6 +167,70 @@ fn admin_create_and_delete() {
assert!(!host.admin(&["create", "Ada", "tools"]).status.success(), "owner names are validated");
}
#[test]
fn deleted_repositories_can_be_restored_until_purged() {
let host = Host::new("admin-trash");
let dir = work("admin-trash-work", "main");
assert!(host.git(&dir, &["push", "-q", "ada@x:ada/tools.git", "main"]).status.success());
assert!(host.admin(&["delete", "ada", "tools", "--yes"]).status.success());
let [entry] = <[String; 1]>::try_from(trash(&host, "ada")).unwrap();
assert!(entry.starts_with("tools."), "{entry}");
let listed = stdout(&host.admin(&["trash"]));
assert!(listed.contains(&format!("ada {entry}")) && listed.contains("deleted 0 days ago"), "{listed}");
// Restoring never replaces what is at the name now.
assert!(host.admin(&["create", "ada", "tools"]).status.success());
let out = host.admin(&["restore", "ada", &entry]);
assert!(!out.status.success());
assert!(stderr(&out).contains("--as"), "{}", stderr(&out));
let out = host.admin(&["restore", "ada", &entry, "--as", "tools-old"]);
assert!(out.status.success(), "{}", stderr(&out));
assert_eq!(git(&host.repo("ada", "tools-old"), &["log", "--format=%s", "main"]), "First");
assert!(trash(&host, "ada").is_empty());
assert!(!host.admin(&["restore", "ada", &entry]).status.success(), "an entry restores once");
assert!(!host.admin(&["restore", "ada", "../../etc"]).status.success(), "entries are validated");
// A purge keeps recent entries and removes old enough ones.
assert!(host.admin(&["delete", "ada", "tools", "--yes"]).status.success());
assert!(host.admin(&["purge"]).status.success());
assert_eq!(trash(&host, "ada").len(), 1, "a fresh entry survives the default purge");
let out = host.admin(&["purge", "--older-than-days", "0"]);
assert!(out.status.success(), "{}", stderr(&out));
assert!(stdout(&out).contains("purged ada/.trash/tools."), "{}", stdout(&out));
assert!(trash(&host, "ada").is_empty());
}
#[test]
fn overwritten_and_deleted_branches_stay_recoverable() {
let host = Host::new("ssh-recovery");
let dir = work("ssh-recovery-work", "main");
let remote = "ada@x:ada/history.git";
assert!(host.git(&dir, &["push", "-q", remote, "main", "main:topic"]).status.success());
let first = git(&dir, &["rev-parse", "HEAD"]);
// Rewrite main and force it over the old commit, then delete topic.
git(&dir, &["commit", "-q", "--amend", "-m", "Rewritten"]);
let rewritten = git(&dir, &["rev-parse", "HEAD"]);
assert!(host.git(&dir, &["push", "-qf", remote, "main"]).status.success());
assert!(host.git(&dir, &["push", "-q", remote, ":topic"]).status.success());
let repo = host.repo("ada", "history");
assert_eq!(git(&repo, &["rev-parse", "main@{1}"]), first, "the reflog keeps the overwritten commit");
let log = fs::read_to_string(repo.join("gitv-push.log")).unwrap();
let lines: Vec<Vec<&str>> = log.lines().map(|l| l.split(' ').skip(1).collect()).collect();
assert_eq!(
lines,
[
vec!["-", first.as_str(), "refs/heads/main"],
vec!["-", first.as_str(), "refs/heads/topic"],
vec![first.as_str(), rewritten.as_str(), "refs/heads/main"],
vec![first.as_str(), "-", "refs/heads/topic"],
],
"{log}"
);
assert_eq!(git(&repo, &["cat-file", "-t", &first]), "commit", "the deleted branch's commit is still there");
}
#[test]
fn admin_add_key() {
let host = Host::new("admin-keys");
@@ -421,7 +499,7 @@ fn creation_never_replaces_what_is_at_the_name() {
}
#[test]
fn deletion_removes_links_inside_a_repository_without_following_them() {
fn purging_removes_links_inside_a_repository_without_following_them() {
let host = Host::new("admin-delete-links");
assert!(host.admin(&["create", "ada", "tools"]).status.success());
let outside = scratch("admin-delete-links-outside");
@@ -430,8 +508,11 @@ fn deletion_removes_links_inside_a_repository_without_following_them() {
let out = host.admin(&["delete", "ada", "tools", "--yes"]);
assert!(out.status.success(), "{}", stderr(&out));
assert!(!host.repo("ada", "tools").exists());
let out = host.admin(&["purge", "--older-than-days", "0"]);
assert!(out.status.success(), "{}", stderr(&out));
assert_eq!(fs::read_to_string(outside.join("precious.txt")).unwrap(), "keep");
assert!(fs::read_dir(host.repos.join("ada")).unwrap().next().is_none(), "no staging directory left behind");
assert!(trash(&host, "ada").is_empty(), "the trash is emptied");
assert_eq!(fs::read_dir(host.repos.join("ada")).unwrap().count(), 1, "only the trash itself is left");
}
#[test]