mobiletto 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/drivers/local/index.js +8 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,9 +66,10 @@ This code would run the same if the driver were `local`.
|
|
|
66
66
|
// * secret: ignored, can be null
|
|
67
67
|
// * opts object:
|
|
68
68
|
// * readOnly: optional, never change anything on the filesystem; default is false
|
|
69
|
-
// *
|
|
69
|
+
// * fileMode: optional, permissions used when creating new files, default is 0600. can be string or integer
|
|
70
|
+
// * dirMode: optional, permissions used when creating new directories, default is 0700. can be string or integer
|
|
70
71
|
// * cacheSize: optional, LRU cache for `list` results
|
|
71
|
-
const local = await mobiletto('local', '/home/ubuntu/tmp', null, {
|
|
72
|
+
const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700', cacheSize: 100})
|
|
72
73
|
|
|
73
74
|
// To use 's3' driver:
|
|
74
75
|
// * key: AWS access key
|
|
@@ -196,6 +197,14 @@ The `mirror` command performs a one-time copy of all files from one mobiletto to
|
|
|
196
197
|
It does not run any process to maintain the mirror over time. Run the `mirror` command again
|
|
197
198
|
to synchronize any missing files.
|
|
198
199
|
|
|
200
|
+
The return value from `mirror` is a simple object with counters for how many files were successfully
|
|
201
|
+
mirrored and how many files had errors:
|
|
202
|
+
|
|
203
|
+
{
|
|
204
|
+
success: count-of-files-mirrored,
|
|
205
|
+
errors: count-of-files-with-errors
|
|
206
|
+
}
|
|
207
|
+
|
|
199
208
|
WARNING: Mirroring large data sets can be very time-consuming and bandwidth-intensive
|
|
200
209
|
|
|
201
210
|
With the `mirror` call semantics it can sometimes be confusing to understand who is the
|
|
@@ -261,7 +270,7 @@ A driver is any JS file that exports a 'storageClient' function with this signat
|
|
|
261
270
|
* `key`: a string, your API key (for the `local` driver this is the base directory)
|
|
262
271
|
* `secret`: a string, your API secret (can be omitted for the `local` driver)
|
|
263
272
|
* `opts`: an object, the properties are per-driver:
|
|
264
|
-
* For `local`, the `
|
|
273
|
+
* For `local`, the `fileMode` and `dirMode` properties determine how new creating files and directories are created
|
|
265
274
|
* For `s3`, the `bucket` property is required. Optional properties are:
|
|
266
275
|
* `region`: the S3 region, default is us-east-1
|
|
267
276
|
* `prefix`: a prefix to prepend to all S3 paths, default is the empty string
|
package/drivers/local/index.js
CHANGED
|
@@ -7,7 +7,8 @@ const {
|
|
|
7
7
|
|
|
8
8
|
const fs = require('fs')
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const DEFAULT_FILE_MODE = '0600'
|
|
11
|
+
const DEFAULT_DIR_MODE = '0700'
|
|
11
12
|
|
|
12
13
|
const isNotExistError = (err) => err.code && (err.code === 'ENOENT' || err.code === 'ENOTDIR')
|
|
13
14
|
|
|
@@ -26,7 +27,8 @@ const fileType = (stat) => {
|
|
|
26
27
|
|
|
27
28
|
class StorageClient {
|
|
28
29
|
baseDir
|
|
29
|
-
|
|
30
|
+
fileMode
|
|
31
|
+
dirMode
|
|
30
32
|
constructor(baseDir, opts) {
|
|
31
33
|
const resolved = this.resolveSymlinks(baseDir)
|
|
32
34
|
if (!resolved.stat.isDirectory()) {
|
|
@@ -35,7 +37,8 @@ class StorageClient {
|
|
|
35
37
|
}
|
|
36
38
|
const dir = resolved.path
|
|
37
39
|
this.baseDir = dir.endsWith('/') ? dir : dir + '/'
|
|
38
|
-
this.
|
|
40
|
+
this.fileMode = opts && opts.fileMode ? opts.fileMode : DEFAULT_FILE_MODE
|
|
41
|
+
this.dirMode = opts && opts.dirMode ? opts.dirMode : DEFAULT_DIR_MODE
|
|
39
42
|
}
|
|
40
43
|
resolveSymlinks (path) {
|
|
41
44
|
let stat = fs.lstatSync(path)
|
|
@@ -151,7 +154,7 @@ class StorageClient {
|
|
|
151
154
|
mkdirs (path) {
|
|
152
155
|
try {
|
|
153
156
|
// console.log(`mkdirs: creating directory: ${path}`)
|
|
154
|
-
fs.mkdirSync(path, {recursive: true, mode: this.
|
|
157
|
+
fs.mkdirSync(path, {recursive: true, mode: this.dirMode})
|
|
155
158
|
} catch (err) {
|
|
156
159
|
throw new MobilettoError(`mkdirs: error creating directory ${path}: ${err}`, err)
|
|
157
160
|
}
|
|
@@ -183,7 +186,7 @@ class StorageClient {
|
|
|
183
186
|
async write (path, generatorOrReadableStream) {
|
|
184
187
|
const file = await this.normalizePathAndEnsureParentDirs(path)
|
|
185
188
|
// console.log(`write: writing path ${path} -> ${file}`)
|
|
186
|
-
const stream = fs.createWriteStream(file, {mode: this.
|
|
189
|
+
const stream = fs.createWriteStream(file, {mode: this.fileMode})
|
|
187
190
|
const writer = writeStream(stream)
|
|
188
191
|
const closer = closeStream(stream)
|
|
189
192
|
let count = 0
|