Better handling of .DS_Store files during migration (#3164)

This commit is contained in:
Opender Singh 2021-03-10 10:45:59 +13:00 committed by GitHub
parent 2d5a78687e
commit dc150ff015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -116,7 +116,7 @@ async function migratePlugins(designerDataDir: string, coreDataDir: string) {
} }
async function readDirs(srcDir: string): Array<string> { async function readDirs(srcDir: string): Array<string> {
if (fs.existsSync(srcDir)) { if (existsAndIsDirectory(srcDir)) {
return await fs.promises.readdir(srcDir); return await fs.promises.readdir(srcDir);
} else { } else {
return []; return [];
@ -129,7 +129,7 @@ async function copyDirs(dirs: Array<string>, srcDir: string, destDir: string) {
const dest = fsPath.join(destDir, dir); const dest = fsPath.join(destDir, dir);
// If source exists, ensure the destination exists, and copy into it // If source exists, ensure the destination exists, and copy into it
if (fs.existsSync(src)) { if (existsAndIsDirectory(src)) {
await fsx.ensureDir(dest); await fsx.ensureDir(dest);
await fsx.copy(src, dest); await fsx.copy(src, dest);
} }
@ -139,12 +139,16 @@ async function copyDirs(dirs: Array<string>, srcDir: string, destDir: string) {
async function removeDirs(dirs: Array<string>, srcDir: string) { async function removeDirs(dirs: Array<string>, srcDir: string) {
for (const dir of dirs.filter(c => c)) { for (const dir of dirs.filter(c => c)) {
const dirToRemove = fsPath.join(srcDir, dir); const dirToRemove = fsPath.join(srcDir, dir);
if (fs.existsSync(dirToRemove)) { if (existsAndIsDirectory(dirToRemove)) {
await fsx.remove(dirToRemove); await fsx.remove(dirToRemove);
} }
} }
} }
export function existsAndIsDirectory(name: string): boolean {
return fs.existsSync(name) && fs.statSync(name).isDirectory();
}
export default async function migrateFromDesigner({ export default async function migrateFromDesigner({
useDesignerSettings, useDesignerSettings,
designerDataDir, designerDataDir,
@ -254,7 +258,7 @@ export async function restoreCoreBackup(backupDir: string, coreDataDir: string)
return; return;
} }
if (!fs.existsSync(backupDir)) { if (!existsAndIsDirectory(backupDir)) {
console.log(`[db-merge] nothing to restore: backup directory doesn't exist at ${backupDir}`); console.log(`[db-merge] nothing to restore: backup directory doesn't exist at ${backupDir}`);
return; return;
} }

View File

@ -4,14 +4,16 @@ import * as React from 'react';
import type { WrapperProps } from './wrapper'; import type { WrapperProps } from './wrapper';
import { ToggleSwitch, Button } from 'insomnia-components'; import { ToggleSwitch, Button } from 'insomnia-components';
import type { MigrationOptions } from '../../common/migrate-from-designer'; import type { MigrationOptions } from '../../common/migrate-from-designer';
import migrateFromDesigner, { restartApp } from '../../common/migrate-from-designer'; import migrateFromDesigner, {
existsAndIsDirectory,
restartApp,
} from '../../common/migrate-from-designer';
import { getDataDirectory, getDesignerDataDir } from '../../common/misc'; import { getDataDirectory, getDesignerDataDir } from '../../common/misc';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import OnboardingContainer from './onboarding-container'; import OnboardingContainer from './onboarding-container';
import { goToNextActivity } from '../redux/modules/global'; import { goToNextActivity } from '../redux/modules/global';
import HelpTooltip from './help-tooltip'; import HelpTooltip from './help-tooltip';
import { trackEvent } from '../../common/analytics'; import { trackEvent } from '../../common/analytics';
import fs from 'fs';
type Step = 'options' | 'migrating' | 'results'; type Step = 'options' | 'migrating' | 'results';
@ -106,9 +108,11 @@ const Options = ({ start, cancel }: OptionsProps) => {
copyPlugins, copyPlugins,
} = options; } = options;
const coreExists = React.useMemo(() => fs.existsSync(coreDataDir), [coreDataDir]); const coreExists = React.useMemo(() => existsAndIsDirectory(coreDataDir), [coreDataDir]);
const designerExists = React.useMemo(() => fs.existsSync(designerDataDir), [designerDataDir]); const designerExists = React.useMemo(() => existsAndIsDirectory(designerDataDir), [
designerDataDir,
]);
const hasSomethingToMigrate = useDesignerSettings || copyWorkspaces || copyPlugins; const hasSomethingToMigrate = useDesignerSettings || copyWorkspaces || copyPlugins;
const dirsExist = coreExists && designerExists; const dirsExist = coreExists && designerExists;