Skip to content

Commit

Permalink
Make path calculations platform-agnostic in export
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Aug 8, 2024
1 parent 1f03ba3 commit f5f928f
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib/import-export/export/exporters/default-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class DefaultExporter extends EventEmitter implements Exporter {
}

const requiredPaths = [
{ path: 'wp-content', isDir: true },
{ path: 'wp-includes', isDir: true },
{ path: [ 'wp-content' ], isDir: true },
{ path: [ 'wp-includes' ], isDir: true },
{ path: 'wp-load.php', isDir: false },
{ path: 'wp-config.php', isDir: false },
];
Expand All @@ -58,8 +58,11 @@ export class DefaultExporter extends EventEmitter implements Exporter {
return requiredPaths.every( ( requiredPath ) =>
this.siteFiles.some( ( file ) => {
const relativePath = path.relative( this.options.site.path, file );
const relativePathItems = relativePath.split( path.sep );
return requiredPath.isDir
? relativePath.startsWith( requiredPath.path )
? ( requiredPath.path as string[] ).every(
( path, index ) => path === relativePathItems[ index ]
)
: relativePath === requiredPath.path;
} )
);
Expand Down Expand Up @@ -208,13 +211,26 @@ export class DefaultExporter extends EventEmitter implements Exporter {
const siteFiles = await this.getSiteFiles();
siteFiles.forEach( ( file ) => {
const relativePath = path.relative( options.site.path, file );
const relativePathItems = relativePath.split( path.sep );
if ( path.basename( file ) === 'wp-config.php' ) {
backupContents.wpConfigFile = file;
} else if ( relativePath.startsWith( 'wp-content/uploads/' ) && options.includes.uploads ) {
} else if (
relativePathItems[ 0 ] === 'wp-content' &&
relativePathItems[ 1 ] === 'uploads' &&
options.includes.uploads
) {
backupContents.wpContent.uploads.push( file );
} else if ( relativePath.startsWith( 'wp-content/plugins/' ) && options.includes.plugins ) {
} else if (
relativePathItems[ 0 ] === 'wp-content' &&
relativePathItems[ 1 ] === 'plugins' &&
options.includes.plugins
) {
backupContents.wpContent.plugins.push( file );
} else if ( relativePath.startsWith( 'wp-content/themes/' ) && options.includes.themes ) {
} else if (
relativePathItems[ 0 ] === 'wp-content' &&
relativePathItems[ 1 ] === 'themes' &&
options.includes.themes
) {
backupContents.wpContent.themes.push( file );
}
} );
Expand Down

0 comments on commit f5f928f

Please sign in to comment.