diff --git a/@xen-orchestra/fs/package.json b/@xen-orchestra/fs/package.json index f5fa24cb5..795b8bdb4 100644 --- a/@xen-orchestra/fs/package.json +++ b/@xen-orchestra/fs/package.json @@ -33,6 +33,7 @@ "limit-concurrency-decorator": "^0.4.0", "lodash": "^4.17.4", "promise-toolbox": "^0.17.0", + "proper-lockfile": "^4.1.2", "readable-stream": "^3.0.6", "through2": "^4.0.2", "tmp": "^0.2.1", diff --git a/@xen-orchestra/fs/src/abstract.js b/@xen-orchestra/fs/src/abstract.js index a07879e65..2df1c4a51 100644 --- a/@xen-orchestra/fs/src/abstract.js +++ b/@xen-orchestra/fs/src/abstract.js @@ -259,6 +259,11 @@ export default class RemoteHandlerAbstract { return entries } + lock(path: string): Promise { + path = normalizePath(path) + return this._lock(path) + } + async mkdir(dir: string, { mode }: { mode?: number } = {}): Promise { await this.__mkdir(normalizePath(dir), { mode }) } @@ -434,6 +439,10 @@ export default class RemoteHandlerAbstract { return {} } + async _lock(path: string): Promise { + return () => Promise.resolve() + } + async _getSize(file: File): Promise { throw new Error('Not implemented') } diff --git a/@xen-orchestra/fs/src/local.js b/@xen-orchestra/fs/src/local.js index 80fb487a5..29af49bf7 100644 --- a/@xen-orchestra/fs/src/local.js +++ b/@xen-orchestra/fs/src/local.js @@ -1,5 +1,6 @@ import df from '@sindresorhus/df' import fs from 'fs-extra' +import lockfile from 'proper-lockfile' import { fromEvent, retry } from 'promise-toolbox' import RemoteHandlerAbstract from './abstract' @@ -82,6 +83,10 @@ export default class LocalHandler extends RemoteHandlerAbstract { return fs.readdir(this._getFilePath(dir)) } + _lock(path) { + return lockfile.lock(path) + } + _mkdir(dir, { mode }) { return fs.mkdir(this._getFilePath(dir), { mode }) } diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index bea03920a..98f3d53f6 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -31,5 +31,6 @@ > > In case of conflict, the highest (lowest in previous list) `$version` wins. +- @xen-orchestra/fs minor - xo-server patch - xo-web patch diff --git a/yarn.lock b/yarn.lock index c29b0e54e..6f4aeb373 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14977,6 +14977,15 @@ proper-lockfile@^4.1.1: retry "^0.12.0" 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: version "1.1.1" resolved "https://registry.yarnpkg.com/protocol-buffers-encodings/-/protocol-buffers-encodings-1.1.1.tgz#f1e4a386711823137330171d2c82b49d062e75d3"