Browse Source

! If the package backup couldn't be created, abort and warn the user.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
f9c05e8b8a

+ 3 - 1
Sources/ManageLanguages.php

@@ -940,7 +940,9 @@ function ModifyLanguage()
 		if (!empty($modSettings['package_make_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['lang_id'] . '$$$'))
 		{
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
-			package_create_backup('backup_lang_' . $context['lang_id']);
+			$result = package_create_backup('backup_lang_' . $context['lang_id']);
+			if (!$result)
+				fatal_lang_error('could_not_language_backup', false);
 		}
 
 		// Second, loop through the array to remove the files.

+ 3 - 1
Sources/Packages.php

@@ -891,7 +891,9 @@ function PackageInstall()
 	{
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
 		// @todo Internationalize this?
-		package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
+		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
+		if (!$result)
+			fatal_lang_error('could_not_language_backup', false);
 	}
 
 	// The mod isn't installed.... unless proven otherwise.

+ 9 - 2
Sources/Subs-Package.php

@@ -2952,15 +2952,20 @@ function package_create_backup($id = 'backup')
 	{
 		$fwrite = 'gzwrite';
 		$fclose = 'gzclose';
-		$output = gzopen($output_file, 'wb');
+		$output = @gzopen($output_file, 'wb');
 	}
 	else
 	{
 		$fwrite = 'fwrite';
 		$fclose = 'fclose';
-		$output = fopen($output_file, 'wb');
+		$output = @fopen($output_file, 'wb');
 	}
 
+	// If we don't have a file handle, that means for whatever reason the file could not be opened.
+	// Could be permissions, could be a file already exists that shouldn't, etc.
+	if (!$output)
+		return false;
+
 	foreach ($files as $real_file => $file)
 	{
 		if (!file_exists($real_file))
@@ -2996,6 +3001,8 @@ function package_create_backup($id = 'backup')
 
 	$fwrite($output, pack('a1024', ''));
 	$fclose($output);
+
+	return true;
 }
 
 /**

+ 1 - 0
Themes/default/languages/Admin.english.php

@@ -603,6 +603,7 @@ $txt['language_description'] = 'This section allows you to edit languages instal
 $txt['language_edit'] = 'Edit Languages';
 $txt['language_add'] = 'Add Language';
 $txt['language_settings'] = 'Settings';
+$txt['could_not_language_backup'] = 'A backup could not be made before removing this language pack. No changes have been made at this time as a result (either change the permissions so Packages/backup can be written to, or turn off backups - not recommended)';
 
 $txt['advanced'] = 'Advanced';
 $txt['simple'] = 'Simple';

+ 2 - 0
Themes/default/languages/Packages.english.php

@@ -34,6 +34,8 @@ $txt['package_delete_list_warning'] = 'Are you sure you wish to clear the instal
 $txt['php_safe_mode'] = 'Sorry, your server currently has PHP set to run in SAFE MODE.  This feature is not compatible with SAFE MODE.';
 $txt['lets_try_anyway'] = 'Let me try anyway.';
 
+$txt['could_not_package_backup'] = 'A backup could not be made before making changes. No changes have been made at this time as a result (either change the permissions so Packages/backup can be written to, or turn off backups - not recommended)';
+
 $txt['package_manager_desc'] = 'From this easy to use interface, you can download and install modifications for use on your forum.';
 $txt['installed_packages_desc'] = 'You can use the interface below to view those packages currently installed on the forum, and remove the ones you no longer require.';
 $txt['download_packages_desc'] = 'From this section you can choose to either download new packages from package servers, or upload a package file directly to the forum.';