[MM-43040] Copy entire config directory over for MAS (#2046)
* [MM-43040] Copy entire config directory over for MAS * Fix package version
This commit is contained in:
909
package-lock.json
generated
909
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -181,6 +181,7 @@
|
||||
"electron-is-dev": "2.0.0",
|
||||
"electron-log": "4.4.6",
|
||||
"electron-updater": "5.0.0",
|
||||
"fs-extra": "10.0.1",
|
||||
"joi": "17.6.0",
|
||||
"pretty-bytes": "6.0.0",
|
||||
"react": "16.14.0",
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import fs from 'fs';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {dialog} from 'electron';
|
||||
|
||||
@@ -15,10 +15,11 @@ import {ServerInfo} from 'main/server/serverInfo';
|
||||
|
||||
import {getDeeplinkingURL, updateServerInfos, resizeScreen, migrateMacAppStore} from './utils';
|
||||
|
||||
jest.mock('fs', () => ({
|
||||
jest.mock('fs-extra', () => ({
|
||||
readFileSync: jest.fn(),
|
||||
writeFileSync: jest.fn(),
|
||||
existsSync: jest.fn(),
|
||||
copySync: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('electron', () => ({
|
||||
@@ -270,19 +271,11 @@ describe('main/app/utils', () => {
|
||||
};
|
||||
JsonFileManager.mockImplementation(() => migrationPrefs);
|
||||
fs.readFileSync.mockReturnValue('config-data');
|
||||
fs.existsSync.mockImplementation((path) => {
|
||||
if (path === '/Library/Application Support/Mattermost') {
|
||||
return true;
|
||||
}
|
||||
return ['config', 'app-state', 'bounds-info', 'migration-info'].some((filename) => path.endsWith(`${filename}.json`));
|
||||
});
|
||||
fs.existsSync.mockReturnValue(true);
|
||||
dialog.showMessageBoxSync.mockReturnValue(0);
|
||||
dialog.showOpenDialogSync.mockReturnValue(['/old/data/path']);
|
||||
migrateMacAppStore();
|
||||
expect(fs.readFileSync).toHaveBeenCalledWith('/old/data/path/config.json');
|
||||
expect(fs.writeFileSync).toHaveBeenCalledWith('/path/to/data/config.json', 'config-data');
|
||||
expect(fs.readFileSync).not.toHaveBeenCalledWith('/old/data/path/allowedProtocols.json');
|
||||
expect(fs.writeFileSync).not.toHaveBeenCalledWith('/path/to/data/allowedProtocols.json', 'config-data');
|
||||
expect(fs.copySync).toHaveBeenCalledWith('/old/data/path', '/path/to/data');
|
||||
expect(updatePaths).toHaveBeenCalled();
|
||||
expect(migrationPrefs.setValue).toHaveBeenCalledWith('masConfigs', true);
|
||||
});
|
||||
|
@@ -1,10 +1,10 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {app, BrowserWindow, Menu, Rectangle, Session, session, dialog, nativeImage} from 'electron';
|
||||
import log, {LevelOption} from 'electron-log';
|
||||
|
||||
@@ -29,8 +29,6 @@ import WindowManager from 'main/windows/windowManager';
|
||||
|
||||
import {mainProtocol} from './initialize';
|
||||
|
||||
const configFileNames = ['config', 'allowedProtocols', 'app-state', 'certificate', 'trustedOrigins', 'bounds-info', 'migration-info'];
|
||||
|
||||
const assetsDir = path.resolve(app.getAppPath(), 'assets');
|
||||
const appIconURL = path.resolve(assetsDir, 'appicon_with_spacing_32.png');
|
||||
const appIcon = nativeImage.createFromPath(appIconURL);
|
||||
@@ -240,12 +238,7 @@ export function migrateMacAppStore() {
|
||||
}
|
||||
|
||||
try {
|
||||
for (const fileName of configFileNames) {
|
||||
if (fs.existsSync(path.resolve(result[0], `${fileName}.json`))) {
|
||||
const contents = fs.readFileSync(path.resolve(result[0], `${fileName}.json`));
|
||||
fs.writeFileSync(path.resolve(app.getPath('userData'), `${fileName}.json`), contents);
|
||||
}
|
||||
}
|
||||
fs.copySync(result[0], app.getPath('userData'));
|
||||
updatePaths(true);
|
||||
migrationPrefs.setValue('masConfigs', true);
|
||||
} catch (e) {
|
||||
|
Reference in New Issue
Block a user