feat(@xen-orchestra/fs): ability to lock a path (#5689)
Related to #5684
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
"limit-concurrency-decorator": "^0.4.0",
|
"limit-concurrency-decorator": "^0.4.0",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"promise-toolbox": "^0.17.0",
|
"promise-toolbox": "^0.17.0",
|
||||||
|
"proper-lockfile": "^4.1.2",
|
||||||
"readable-stream": "^3.0.6",
|
"readable-stream": "^3.0.6",
|
||||||
"through2": "^4.0.2",
|
"through2": "^4.0.2",
|
||||||
"tmp": "^0.2.1",
|
"tmp": "^0.2.1",
|
||||||
|
|||||||
@@ -259,6 +259,11 @@ export default class RemoteHandlerAbstract {
|
|||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock(path: string): Promise<Function> {
|
||||||
|
path = normalizePath(path)
|
||||||
|
return this._lock(path)
|
||||||
|
}
|
||||||
|
|
||||||
async mkdir(dir: string, { mode }: { mode?: number } = {}): Promise<void> {
|
async mkdir(dir: string, { mode }: { mode?: number } = {}): Promise<void> {
|
||||||
await this.__mkdir(normalizePath(dir), { mode })
|
await this.__mkdir(normalizePath(dir), { mode })
|
||||||
}
|
}
|
||||||
@@ -434,6 +439,10 @@ export default class RemoteHandlerAbstract {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _lock(path: string): Promise<Function> {
|
||||||
|
return () => Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
async _getSize(file: File): Promise<number> {
|
async _getSize(file: File): Promise<number> {
|
||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import df from '@sindresorhus/df'
|
import df from '@sindresorhus/df'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
import lockfile from 'proper-lockfile'
|
||||||
import { fromEvent, retry } from 'promise-toolbox'
|
import { fromEvent, retry } from 'promise-toolbox'
|
||||||
|
|
||||||
import RemoteHandlerAbstract from './abstract'
|
import RemoteHandlerAbstract from './abstract'
|
||||||
@@ -82,6 +83,10 @@ export default class LocalHandler extends RemoteHandlerAbstract {
|
|||||||
return fs.readdir(this._getFilePath(dir))
|
return fs.readdir(this._getFilePath(dir))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lock(path) {
|
||||||
|
return lockfile.lock(path)
|
||||||
|
}
|
||||||
|
|
||||||
_mkdir(dir, { mode }) {
|
_mkdir(dir, { mode }) {
|
||||||
return fs.mkdir(this._getFilePath(dir), { mode })
|
return fs.mkdir(this._getFilePath(dir), { mode })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,5 +31,6 @@
|
|||||||
>
|
>
|
||||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||||
|
|
||||||
|
- @xen-orchestra/fs minor
|
||||||
- xo-server patch
|
- xo-server patch
|
||||||
- xo-web patch
|
- xo-web patch
|
||||||
|
|||||||
@@ -14977,6 +14977,15 @@ proper-lockfile@^4.1.1:
|
|||||||
retry "^0.12.0"
|
retry "^0.12.0"
|
||||||
signal-exit "^3.0.2"
|
signal-exit "^3.0.2"
|
||||||
|
|
||||||
|
proper-lockfile@^4.1.2:
|
||||||
|
version "4.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.2.tgz#c8b9de2af6b2f1601067f98e01ac66baa223141f"
|
||||||
|
integrity sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==
|
||||||
|
dependencies:
|
||||||
|
graceful-fs "^4.2.4"
|
||||||
|
retry "^0.12.0"
|
||||||
|
signal-exit "^3.0.2"
|
||||||
|
|
||||||
protocol-buffers-encodings@^1.1.0:
|
protocol-buffers-encodings@^1.1.0:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/protocol-buffers-encodings/-/protocol-buffers-encodings-1.1.1.tgz#f1e4a386711823137330171d2c82b49d062e75d3"
|
resolved "https://registry.yarnpkg.com/protocol-buffers-encodings/-/protocol-buffers-encodings-1.1.1.tgz#f1e4a386711823137330171d2c82b49d062e75d3"
|
||||||
|
|||||||
Reference in New Issue
Block a user