Skip to content

Commit de6e704

Browse files
authored
Merge da5de3e into 123579e
2 parents 123579e + da5de3e commit de6e704

2 files changed

Lines changed: 98 additions & 19 deletions

File tree

‎src/lib/import-export/export/exporters/default-exporter.ts‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,28 @@ export class DefaultExporter extends EventEmitter implements Exporter {
2626
private archiveBuilder!: archiver.Archiver;
2727
private backup: BackupContents;
2828
private readonly options: ExportOptions;
29-
private readonly pathsToExclude = [
30-
'wp-content/mu-plugins/sqlite-database-integration',
31-
'wp-content/mu-plugins/0-allowed-redirect-hosts.php',
32-
'wp-content/mu-plugins/0-check-theme-availability.php',
33-
'wp-content/mu-plugins/0-deactivate-jetpack-modules.php',
34-
'wp-content/mu-plugins/0-dns-functions.php',
35-
'wp-content/mu-plugins/0-permalinks.php',
36-
'wp-content/mu-plugins/0-wp-config-constants-polyfill.php',
37-
'wp-content/mu-plugins/0-sqlite.php',
38-
'wp-content/mu-plugins/0-thumbnails.php',
39-
'wp-content/mu-plugins/0-https-for-reverse-proxy.php',
40-
'wp-content/mu-plugins/0-sqlite-command.php',
41-
];
29+
30+
private isExcludedPath( pathToCheck: string ) {
31+
const pathsToExclude = [
32+
'wp-content/mu-plugins/sqlite-database-integration',
33+
'wp-content/database',
34+
'wp-content/db.php',
35+
'wp-content/debug.log',
36+
'wp-content/mu-plugins/0-allowed-redirect-hosts.php',
37+
'wp-content/mu-plugins/0-check-theme-availability.php',
38+
'wp-content/mu-plugins/0-deactivate-jetpack-modules.php',
39+
'wp-content/mu-plugins/0-dns-functions.php',
40+
'wp-content/mu-plugins/0-permalinks.php',
41+
'wp-content/mu-plugins/0-wp-config-constants-polyfill.php',
42+
'wp-content/mu-plugins/0-sqlite.php',
43+
'wp-content/mu-plugins/0-thumbnails.php',
44+
'wp-content/mu-plugins/0-https-for-reverse-proxy.php',
45+
'wp-content/mu-plugins/0-sqlite-command.php',
46+
];
47+
return pathsToExclude.some( ( pathToExclude ) =>
48+
pathToCheck.startsWith( path.normalize( pathToExclude ) )
49+
);
50+
}
4251

4352
constructor( options: ExportOptions ) {
4453
super();
@@ -177,11 +186,8 @@ export class DefaultExporter extends EventEmitter implements Exporter {
177186
if ( stat.isDirectory() ) {
178187
this.archiveBuilder.directory( fullPath, archivePath, ( entry ) => {
179188
const fullArchivePath = path.join( archivePath, entry.name );
180-
const isExcluded = this.pathsToExclude.some( ( pathToExclude ) =>
181-
fullArchivePath.startsWith( path.normalize( pathToExclude ) )
182-
);
183189
if (
184-
isExcluded ||
190+
this.isExcludedPath( fullArchivePath ) ||
185191
entry.name.includes( '.git' ) ||
186192
entry.name.includes( 'node_modules' ) ||
187193
entry.name.includes( 'cache' )
@@ -191,6 +197,9 @@ export class DefaultExporter extends EventEmitter implements Exporter {
191197
return entry;
192198
} );
193199
} else {
200+
if ( this.isExcludedPath( archivePath ) ) {
201+
continue;
202+
}
194203
this.archiveBuilder.file( fullPath, { name: archivePath } );
195204
}
196205
}

‎src/lib/import-export/tests/export/exporters/default-exporter.test.ts‎

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,23 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => {
132132
isFile: () => true,
133133
},
134134
{
135-
path: normalize( '/path/to/site' ),
136-
name: 'wp-config.php',
135+
path: normalize( '/path/to/site/wp-content' ),
136+
name: 'debug.log',
137+
isFile: () => true,
138+
},
139+
{
140+
path: normalize( '/path/to/site/wp-content' ),
141+
name: 'db.php',
142+
isFile: () => true,
143+
},
144+
{
145+
path: normalize( '/path/to/site/wp-content/database' ),
146+
name: '.ht.sqlite',
147+
isFile: () => true,
148+
},
149+
{
150+
path: normalize( '/path/to/site/wp-content/mu-plugins/sqlite-database-integration' ),
151+
name: 'example-load.php',
137152
isFile: () => true,
138153
},
139154
];
@@ -569,4 +584,59 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => {
569584
sqlFiles: [],
570585
} );
571586
} );
587+
588+
it( "shouldn't include files like database, db.php and debug.log to the archive, even if specified", async () => {
589+
const options = {
590+
...mockOptions,
591+
includes: {
592+
database: true,
593+
wpContent: true,
594+
},
595+
specificSelectionPaths: [
596+
'database/.ht.sqlite',
597+
'db.php',
598+
'debug.log',
599+
'mu-plugins/sqlite-database-integration/example-load.php',
600+
],
601+
};
602+
603+
const exporter = new DefaultExporter( options );
604+
await exporter.export();
605+
606+
expect( fsPromises.stat ).toHaveBeenCalledWith(
607+
normalize( '/path/to/site/wp-content/debug.log' )
608+
);
609+
expect( mockArchiver.file ).not.toHaveBeenCalledWith(
610+
normalize( '/path/to/site/wp-content/debug.log' ),
611+
{ name: 'wp-content/debug.log' }
612+
);
613+
614+
expect( fsPromises.stat ).toHaveBeenCalledWith(
615+
normalize( '/path/to/site/wp-content/db.php' )
616+
);
617+
expect( mockArchiver.file ).not.toHaveBeenCalledWith(
618+
normalize( '/path/to/site/wp-content/db.php' ),
619+
{ name: 'wp-content/db.php' }
620+
);
621+
622+
expect( fsPromises.stat ).toHaveBeenCalledWith(
623+
normalize( '/path/to/site/wp-content/database/.ht.sqlite' )
624+
);
625+
expect( mockArchiver.file ).not.toHaveBeenCalledWith(
626+
normalize( '/path/to/site/wp-content/database/.ht.sqlite' ),
627+
{ name: 'wp-content/database/.ht.sqlite' }
628+
);
629+
630+
expect( fsPromises.stat ).toHaveBeenCalledWith(
631+
normalize(
632+
'/path/to/site/wp-content/mu-plugins/sqlite-database-integration/example-load.php'
633+
)
634+
);
635+
expect( mockArchiver.file ).not.toHaveBeenCalledWith(
636+
normalize(
637+
'/path/to/site/wp-content/mu-plugins/sqlite-database-integration/example-load.php'
638+
),
639+
{ name: 'wp-content/mu-plugins/sqlite-database-integration/example-load.php' }
640+
);
641+
} );
572642
} );

0 commit comments

Comments
 (0)