Skip to content

Commit

Permalink
fix: recurring ENOENT errors when processing export requests (#30063)
Browse files Browse the repository at this point in the history
* fix: unable to create user if user manual approval is enabled

* don't create directories when scheduling, create them when actually
running

* come on

* oops

* sorry

* add changeset

* oh you linter
  • Loading branch information
debdutdeb authored Aug 10, 2023
1 parent ea89986 commit 2cf2643
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-walls-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed failing user data exports
6 changes: 6 additions & 0 deletions apps/meteor/server/lib/dataExport/processDataDownloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const generateUserFile = async (exportOperation: IExportOperation, userData?: IU
return;
}

await mkdir(exportOperation.exportPath, { recursive: true });

const { username, name, statusText, emails, roles, services } = userData;

const dataToSave = {
Expand Down Expand Up @@ -101,6 +103,8 @@ const generateUserAvatarFile = async (exportOperation: IExportOperation, userDat
return;
}

await mkdir(exportOperation.exportPath, { recursive: true });

const file = await Avatars.findOneByName(userData.username);
if (!file) {
return;
Expand All @@ -117,6 +121,8 @@ const generateChannelsFile = async (type: 'json' | 'html', exportPath: string, e
return;
}

await mkdir(exportOperation.exportPath, { recursive: true });

const fileName = joinPath(exportPath, 'channels.json');
await writeFile(
fileName,
Expand Down
5 changes: 1 addition & 4 deletions apps/meteor/server/methods/requestDataDownload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, mkdtemp } from 'fs/promises';
import { mkdtemp } from 'fs/promises';
import { tmpdir } from 'os';
import path, { join } from 'path';

Expand Down Expand Up @@ -65,7 +65,6 @@ Meteor.methods<ServerMethods>({
}

const tempFolder = settings.get<string | undefined>('UserData_FileSystemPath')?.trim() || (await mkdtemp(join(tmpdir(), 'userData')));
await mkdir(tempFolder, { recursive: true });

const exportOperation = {
status: 'preparing',
Expand All @@ -81,10 +80,8 @@ Meteor.methods<ServerMethods>({
exportOperation._id = id;

const folderName = path.join(tempFolder, id);
await mkdir(folderName, { recursive: true });

const assetsFolder = path.join(folderName, 'assets');
await mkdir(assetsFolder, { recursive: true });

exportOperation.exportPath = folderName;
exportOperation.assetsPath = assetsFolder;
Expand Down

0 comments on commit 2cf2643

Please sign in to comment.