@@ -12,9 +12,12 @@ a = require('@cocalc/file-server/btrfs'); fs = await a.filesystem({device:'/tmp/
12
12
*/
13
13
14
14
import refCache from "@cocalc/util/refcache" ;
15
- import { exists , mkdirp , btrfs , sudo } from "./util" ;
15
+ import { mkdirp , btrfs , sudo } from "./util" ;
16
16
import { join } from "path" ;
17
17
import { Subvolumes } from "./subvolumes" ;
18
+ import { mkdir } from "fs/promises" ;
19
+ import { exists } from "@cocalc/backend/misc/async-utils-node" ;
20
+ import { executeCode } from "@cocalc/backend/execute-code" ;
18
21
19
22
// default size of btrfs filesystem if creating an image file.
20
23
const DEFAULT_FILESYSTEM_SIZE = "10G" ;
@@ -45,7 +48,6 @@ export interface Options {
45
48
export class Filesystem {
46
49
public readonly opts : Options ;
47
50
public readonly bup : string ;
48
- public readonly streams : string ;
49
51
public readonly subvolumes : Subvolumes ;
50
52
51
53
constructor ( opts : Options ) {
@@ -56,26 +58,30 @@ export class Filesystem {
56
58
} ;
57
59
this . opts = opts ;
58
60
this . bup = join ( this . opts . mount , "bup" ) ;
59
- this . streams = join ( this . opts . mount , "streams" ) ;
60
61
this . subvolumes = new Subvolumes ( this ) ;
61
62
}
62
63
63
64
init = async ( ) => {
64
- await mkdirp (
65
- [ this . opts . mount , this . streams , this . bup ] . filter ( ( x ) => x ) as string [ ] ,
66
- ) ;
65
+ await mkdirp ( [ this . opts . mount ] ) ;
67
66
await this . initDevice ( ) ;
68
67
await this . mountFilesystem ( ) ;
69
68
await sudo ( { command : "chmod" , args : [ "a+rx" , this . opts . mount ] } ) ;
70
69
await btrfs ( {
71
70
args : [ "quota" , "enable" , "--simple" , this . opts . mount ] ,
72
71
} ) ;
72
+ await this . initBup ( ) ;
73
+ } ;
74
+
75
+ unmount = async ( ) => {
73
76
await sudo ( {
74
- bash : true ,
75
- command : `BUP_DIR=${ this . bup } bup init` ,
77
+ command : "umount" ,
78
+ args : [ this . opts . mount ] ,
79
+ err_on_exit : true ,
76
80
} ) ;
77
81
} ;
78
82
83
+ close = ( ) => { } ;
84
+
79
85
private initDevice = async ( ) => {
80
86
if ( ! isImageFile ( this . opts . device ) ) {
81
87
// raw block device -- nothing to do
@@ -125,6 +131,10 @@ export class Filesystem {
125
131
}
126
132
} ;
127
133
134
+ private formatDevice = async ( ) => {
135
+ await sudo ( { command : "mkfs.btrfs" , args : [ this . opts . device ] } ) ;
136
+ } ;
137
+
128
138
private _mountFilesystem = async ( ) => {
129
139
const args : string [ ] = isImageFile ( this . opts . device ) ? [ "-o" , "loop" ] : [ ] ;
130
140
args . push (
@@ -162,19 +172,16 @@ export class Filesystem {
162
172
return { stderr, exit_code } ;
163
173
} ;
164
174
165
- unmount = async ( ) => {
166
- await sudo ( {
167
- command : "umount" ,
168
- args : [ this . opts . mount ] ,
169
- err_on_exit : true ,
175
+ private initBup = async ( ) => {
176
+ if ( ! ( await exists ( this . bup ) ) ) {
177
+ await mkdir ( this . bup ) ;
178
+ }
179
+ await executeCode ( {
180
+ command : "bup" ,
181
+ args : [ "init" ] ,
182
+ env : { BUP_DIR : this . bup } ,
170
183
} ) ;
171
184
} ;
172
-
173
- private formatDevice = async ( ) => {
174
- await sudo ( { command : "mkfs.btrfs" , args : [ this . opts . device ] } ) ;
175
- } ;
176
-
177
- close = ( ) => { } ;
178
185
}
179
186
180
187
function isImageFile ( name : string ) {
0 commit comments