CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/delete-files.ts
Views: 687
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
9
// NOTE: there are also .term files in subframes with history that doesn't get
10
// deleted. That's an edge case.
11
12
// This *includes* path.
13
export function deleted_file_variations(path: string): string[] {
14
let { head, tail } = path_split(path);
15
if (head != "") {
16
head = head + "/";
17
}
18
const variations: string[] = [path];
19
for (const ext of [
20
"sage-chat",
21
"sage-jupyter",
22
"sage-jupyter2",
23
"time-travel",
24
"sage-history",
25
"syncdb",
26
]) {
27
variations.push(head + hidden_meta_file(tail, ext));
28
}
29
return variations;
30
}
31
32
// This does NOT include {src,dest}.
33
export function move_file_variations(
34
src: string,
35
dest: string,
36
): { src: string; dest: string }[] {
37
let { head, tail } = path_split(src);
38
if (head != "") {
39
head = head + "/";
40
}
41
const d = path_split(dest);
42
if (d.head != "") {
43
d.head = d.head + "/";
44
}
45
const variations: { src: string; dest: string }[] = [];
46
for (const ext of [
47
"sage-chat",
48
"sage-jupyter",
49
"sage-jupyter2",
50
"time-travel",
51
"sage-history",
52
]) {
53
variations.push({
54
src: head + "." + tail + "." + ext,
55
dest: d.head + "." + d.tail + "." + ext,
56
});
57
}
58
return variations;
59
}
60
61