'om_disk_space', 'message' => sprintf( /* translators: 1: space needed, 2: space free */ __( 'Not enough free disk space to restore this backup: about %1$s is needed and %2$s is free. Nothing was changed.', 'migratex' ), Format::bytes( $needed ), Format::bytes( (int) $free ) ), ); } // Files are moved from the job folder into wp-content. On another disk that is a copy, which needs room there too. if ( ! self::sameDisk( $job_dir, Paths::content() ) ) { $free_content = Environment::freeDiskSpace( Paths::content() ); if ( null !== $free_content && $free_content < $payload + self::MIN_HEADROOM ) { return array( 'code' => 'om_disk_space', 'message' => sprintf( /* translators: 1: space needed, 2: space free */ __( 'Not enough free disk space in wp-content to restore this backup: about %1$s is needed and %2$s is free. Nothing was changed.', 'migratex' ), Format::bytes( $payload + self::MIN_HEADROOM ), Format::bytes( (int) $free_content ) ), ); } } // Where the archive is unpacked first. if ( ! wp_mkdir_p( $job_dir ) || ! Environment::canWriteTo( $job_dir ) ) { return self::notWritable( 'wp-content/uploads/' . basename( Paths::root() ) ); } // Where its files end up. $content = Paths::content(); foreach ( array_unique( $roots ) as $root ) { $dir = '' === $root ? $content : $content . '/' . $root; // A folder that does not exist yet is created inside wp-content, so that must be writable. $target = is_dir( $dir ) ? $dir : $content; if ( ! Environment::canWriteTo( $target ) ) { return self::notWritable( 'wp-content' . ( is_dir( $dir ) && '' !== $root ? '/' . $root : '' ) ); } } return null; } /** * @return array{code:string,message:string} */ private static function notWritable( string $folder ): array { return array( 'code' => 'om_not_writable', 'message' => sprintf( /* translators: %s: folder path */ __( 'The folder %s is not writable by WordPress, so this backup cannot be restored here. Fix its permissions and try again. Nothing was changed.', 'migratex' ), $folder ), ); } private static function sameDisk( string $a, string $b ): bool { $device = static function ( string $path ) { while ( ! is_dir( $path ) && dirname( $path ) !== $path ) { $path = dirname( $path ); } $stat = @stat( $path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- unknown means "assume the same disk". return is_array( $stat ) ? $stat['dev'] : null; }; $da = $device( $a ); $db = $device( $b ); return null === $da || null === $db || $da === $db; } }