Index: src/wp-admin/includes/ms.php
===================================================================
--- src/wp-admin/includes/ms.php	(revision 30403)
+++ src/wp-admin/includes/ms.php	(working copy)
@@ -85,11 +85,24 @@
 
 	$current_site = get_current_site();
 
+	// If a full blog object is not available, do not destroy anything.
+	if ( $drop && ! $blog ) {
+		$drop = false;
+	}
+
 	// Don't destroy the initial, main, or root blog.
-	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
+	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
+		$drop = false;
+	}
+
+	// If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
+	if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( get_option( 'upload_path' ) ) ) {
 		$drop = false;
+	}
 
 	if ( $drop ) {
+		$uploads = wp_upload_dir();
+
 		$tables = $wpdb->tables( 'blog' );
 		/**
 		 * Filter the tables to drop when the blog is deleted.
@@ -107,7 +120,6 @@
 
 		$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
 
-		$uploads = wp_upload_dir();
 		/**
 		 * Filter the upload base directory to delete when the blog is deleted.
 		 *
Index: tests/phpunit/tests/multisite/ms-files-rewriting.php
===================================================================
--- tests/phpunit/tests/multisite/ms-files-rewriting.php	(revision 30403)
+++ tests/phpunit/tests/multisite/ms-files-rewriting.php	(working copy)
@@ -55,6 +55,37 @@
 		$this->assertEquals( '', $info2['error'] );
 		restore_current_blog();
 	}
+
+	/**
+	 * When a site is deleted with wpmu_delete_blog(), only the files associated with
+	 * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
+	 * should change with upload directories.
+	 */
+	function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
+		$filename = rand_str().'.jpg';
+		$contents = rand_str();
+
+		// Upload a file to the main site on the network.
+		$file1 = wp_upload_bits( $filename, null, $contents );
+
+		$blog_id = $this->factory->blog->create();
+
+		switch_to_blog( $blog_id );
+		$file2 = wp_upload_bits( $filename, null, $contents );
+		restore_current_blog();
+
+		wpmu_delete_blog( $blog_id, true );
+
+		// The file on the main site should still exist. The file on the deleted site should not.
+		$this->assertTrue( file_exists( $file1['file'] ) );
+		$this->assertFalse( file_exists( $file2['file'] ) );
+
+		wpmu_delete_blog( $blog_id, true );
+
+		// The file on the main site should still exist. The file on the deleted site should not.
+		$this->assertTrue( file_exists( $file1['file'] ) );
+		$this->assertFalse( file_exists( $file2['file'] ) );
+	}
 }
 
 endif;
\ No newline at end of file
Index: tests/phpunit/tests/multisite/site.php
===================================================================
--- tests/phpunit/tests/multisite/site.php	(revision 30403)
+++ tests/phpunit/tests/multisite/site.php	(working copy)
@@ -274,6 +274,37 @@
 		$this->assertEquals( 1, get_blog_count() );
 	}
 
+	/**
+	 * When a site is deleted with wpmu_delete_blog(), only the files associated with
+	 * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
+	 * should change with upload directories.
+	 */
+	function test_upload_directories_after_multiple_wpmu_delete_blog() {
+		$filename = rand_str().'.jpg';
+		$contents = rand_str();
+
+		// Upload a file to the main site on the network.
+		$file1 = wp_upload_bits( $filename, null, $contents );
+
+		$blog_id = $this->factory->blog->create();
+
+		switch_to_blog( $blog_id );
+		$file2 = wp_upload_bits( $filename, null, $contents );
+		restore_current_blog();
+
+		wpmu_delete_blog( $blog_id, true );
+
+		// The file on the main site should still exist. The file on the deleted site should not.
+		$this->assertTrue( file_exists( $file1['file'] ) );
+		$this->assertFalse( file_exists( $file2['file'] ) );
+
+		wpmu_delete_blog( $blog_id, true );
+
+		// The file on the main site should still exist. The file on the deleted site should not.
+		$this->assertTrue( file_exists( $file1['file'] ) );
+		$this->assertFalse( file_exists( $file2['file'] ) );
+	}
+
 	function test_wpmu_update_blogs_date() {
 		global $wpdb;
 
