From 4d40b56d85c6889645de4fc7ea8e3c0d1da4ccbd Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 23 Jun 2022 16:37:56 +0200 Subject: [PATCH] fix(xo-server/file restore): ignore non-regular files/dirs (#6305) Fixes zammad#7648 This also ignore (broken and valid) symlinks. --- @xen-orchestra/backups/RemoteAdapter.js | 23 +++++++++++++---------- CHANGELOG.unreleased.md | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/@xen-orchestra/backups/RemoteAdapter.js b/@xen-orchestra/backups/RemoteAdapter.js index 605e33354..103829236 100644 --- a/@xen-orchestra/backups/RemoteAdapter.js +++ b/@xen-orchestra/backups/RemoteAdapter.js @@ -15,7 +15,7 @@ const { deduped } = require('@vates/disposable/deduped.js') const { decorateMethodsWith } = require('@vates/decorate-with') const { compose } = require('@vates/compose') const { execFile } = require('child_process') -const { readdir, stat } = require('fs-extra') +const { readdir, lstat } = require('fs-extra') const { v4: uuidv4 } = require('uuid') const { ZipFile } = require('yazl') const zlib = require('zlib') @@ -47,13 +47,12 @@ const resolveSubpath = (root, path) => resolve(root, `.${resolve('/', path)}`) const RE_VHDI = /^vhdi(\d+)$/ async function addDirectory(files, realPath, metadataPath) { - try { - const subFiles = await readdir(realPath) - await asyncMap(subFiles, file => addDirectory(files, realPath + '/' + file, metadataPath + '/' + file)) - } catch (error) { - if (error == null || error.code !== 'ENOTDIR') { - throw error - } + const stats = await lstat(realPath) + if (stats.isDirectory()) { + await asyncMap(await readdir(realPath), file => + addDirectory(files, realPath + '/' + file, metadataPath + '/' + file) + ) + } else if (stats.isFile()) { files.push({ realPath, metadataPath, @@ -383,8 +382,12 @@ class RemoteAdapter { const entriesMap = {} await asyncMap(await readdir(path), async name => { try { - const stats = await stat(`${path}/${name}`) - entriesMap[stats.isDirectory() ? `${name}/` : name] = {} + const stats = await lstat(`${path}/${name}`) + if (stats.isDirectory()) { + entriesMap[name + '/'] = {} + } else if (stats.isFile()) { + entriesMap[name] = {} + } } catch (error) { if (error == null || error.code !== 'ENOENT') { throw error diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 8347a32fd..6590c2d32 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -16,6 +16,7 @@ - [VDI Import] Fix `this._getOrWaitObject is not a function` - [VM] Attempting to delete a protected VM should display a modal with the error and the ability to bypass it (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) - [OVA Import] Fix import stuck after first disk +- [File restore] Ignore symbolic links ### Packages to release