Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/delete-files.ts
1447 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { path_split } from "./misc";
7
import { hidden_meta_file } from "@cocalc/util/misc";
8
import { JUPYTER_SYNCDB_EXTENSIONS } from "@cocalc/util/jupyter/names";
9
10
// NOTE: there are also .term files in subframes with history that doesn't get
11
// deleted. That's an edge case.
12
13
// This *includes* path.
14
export function deleted_file_variations(path: string): string[] {
15
let { head, tail } = path_split(path);
16
if (head != "") {
17
head = head + "/";
18
}
19
const variations: string[] = [path];
20
for (const ext of [
21
"sage-chat",
22
"sage-jupyter",
23
JUPYTER_SYNCDB_EXTENSIONS,
24
"time-travel",
25
"sage-history",
26
"syncdb",
27
]) {
28
variations.push(head + hidden_meta_file(tail, ext));
29
}
30
return variations;
31
}
32
33
// This does NOT include {src,dest}.
34
export function move_file_variations(
35
src: string,
36
dest: string,
37
): { src: string; dest: string }[] {
38
let { head, tail } = path_split(src);
39
if (head != "") {
40
head = head + "/";
41
}
42
const d = path_split(dest);
43
if (d.head != "") {
44
d.head = d.head + "/";
45
}
46
const variations: { src: string; dest: string }[] = [];
47
for (const ext of [
48
"sage-chat",
49
"sage-jupyter",
50
JUPYTER_SYNCDB_EXTENSIONS,
51
"time-travel",
52
"sage-history",
53
]) {
54
variations.push({
55
src: head + "." + tail + "." + ext,
56
dest: d.head + "." + d.tail + "." + ext,
57
});
58
}
59
return variations;
60
}
61
62