mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-23 06:12:23 +00:00
fix: Ignore symbolic links in data during backup (#28132)
Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
This commit is contained in:
1 parent
c12f07c5a0
commit
0182c4b32e
2 files changed
+18
-5
No files matched your search
+12
-5
@@ -202,14 +202,21 @@ function containsControlCharacter(str: string): boolean {
|
||||
|
||||
function getAllFiles(path_: string): string[] {
|
||||
const result = [];
|
||||
for (let item of fs.readdirSync(path_)) {
|
||||
item = path.join(path_, item);
|
||||
if (fs.lstatSync(item).isFile()) {
|
||||
result.push(item);
|
||||
|
||||
for (const item of fs.readdirSync(path_, {withFileTypes: true})) {
|
||||
if (item.isSymbolicLink()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fileName = path.join(path_, item.name);
|
||||
|
||||
if (fs.lstatSync(fileName).isFile()) {
|
||||
result.push(fileName);
|
||||
} else {
|
||||
result.push(...getAllFiles(item));
|
||||
result.push(...getAllFiles(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {CUSTOM_CLUSTERS, devices, groups, mockController as mockZHController, ev
|
||||
|
||||
import assert from "node:assert";
|
||||
import fs from "node:fs";
|
||||
import {platform} from "node:os";
|
||||
import path from "node:path";
|
||||
import stringify from "json-stable-stringify-without-jsonify";
|
||||
import type {Mock} from "vitest";
|
||||
@@ -3841,6 +3842,11 @@ describe("Extension: Bridge", () => {
|
||||
fs.writeFileSync(path.join(data.mockDir, "log", "log.log"), "test123");
|
||||
fs.mkdirSync(path.join(data.mockDir, "ext_converters", "123"));
|
||||
fs.writeFileSync(path.join(data.mockDir, "ext_converters", "123", "myfile.js"), "test123");
|
||||
fs.symlinkSync(
|
||||
path.join(data.mockDir, "ext_converters"),
|
||||
path.join(data.mockDir, "ext_converters_sym"),
|
||||
platform() === "win32" ? "junction" : "dir",
|
||||
);
|
||||
mockMQTTPublishAsync.mockClear();
|
||||
mockMQTTEvents.message("zigbee2mqtt/bridge/request/backup", "");
|
||||
await flushPromises();
|
||||
|
||||
Reference in new issue
Block a user