Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: lib/filestorage/file_exceptions.php
- ===================================================================
- RCS file: /cvsroot/moodle/moodle/lib/filestorage/file_exceptions.php,v
- retrieving revision 1.2
- diff -u -r1.2 file_exceptions.php
- --- lib/filestorage/file_exceptions.php 21 Sep 2010 07:59:27 -0000 1.2
- +++ lib/filestorage/file_exceptions.php 27 Nov 2010 12:00:31 -0000
- @@ -83,8 +83,15 @@
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
- -class file_pool_content_exception extends file_exception {
- - function __construct($contenthash, $debuginfo = NULL) {
- - parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
- +class file_pool_put_exception extends file_exception {
- + function __construct($contenthash, $content, $sourcefilepath, $debuginfo = null) {
- + $a = new stdClass();
- + $a->hash = $contenthash;
- + if (!is_null($content)) {
- + $a->source = 'string: ' . shorten_text($content);
- + } else {
- + $a->source = 'file: ' . $sourcefilepath;
- + }
- + parent::__construct('hashpoolproblem', $a, $debuginfo);
- }
- }
- Index: lib/filestorage/file_storage.php
- ===================================================================
- RCS file: /cvsroot/moodle/moodle/lib/filestorage/file_storage.php,v
- retrieving revision 1.10
- diff -u -r1.10 file_storage.php
- --- lib/filestorage/file_storage.php 11 Nov 2010 18:58:06 -0000 1.10
- +++ lib/filestorage/file_storage.php 27 Nov 2010 12:00:31 -0000
- @@ -1022,37 +1022,7 @@
- }
- $filesize = filesize($pathname);
- -
- - $hashpath = $this->path_from_hash($contenthash);
- - $hashfile = "$hashpath/$contenthash";
- -
- - if (file_exists($hashfile)) {
- - if (filesize($hashfile) !== $filesize) {
- - throw new file_pool_content_exception($contenthash);
- - }
- - $newfile = false;
- -
- - } else {
- - if (!is_dir($hashpath)) {
- - if (!mkdir($hashpath, $this->dirpermissions, true)) {
- - throw new file_exception('storedfilecannotcreatefiledirs'); // permission trouble
- - }
- - }
- - $newfile = true;
- -
- - if (!copy($pathname, $hashfile)) {
- - throw new file_exception('storedfilecannotread');
- - }
- -
- - if (filesize($hashfile) !== $filesize) {
- - @unlink($hashfile);
- - throw new file_pool_content_exception($contenthash);
- - }
- - chmod($hashfile, $this->filepermissions); // fix permissions if needed
- - }
- -
- -
- - return array($contenthash, $filesize, $newfile);
- + return $this->put_file_in_pool($filesize, $contenthash, null, $pathname);
- }
- /**
- @@ -1064,14 +1034,27 @@
- public function add_string_to_pool($content) {
- $contenthash = sha1($content);
- $filesize = strlen($content); // binary length
- + return $this->put_file_in_pool($filesize, $contenthash, $content, null);
- + }
- +
- + /**
- + * Actually do the work of adding something to the sha1 pool. Used by
- + * {@link add_string_to_pool()} and {@link add_file_to_pool()}
- + *
- + * @param string $content file content - binary string
- + * @return array (contenthash, filesize, newfile)
- + */
- + protected function put_file_in_pool($filesize, $contenthash, $content, $sourcefilepath) {
- + if (is_null($content) != is_null($sourcefilepath)) {
- + throw new coding_exception('Exactly one of $content and $sourcefilepath must be non-null when calling put_file_in_pool.');
- + }
- $hashpath = $this->path_from_hash($contenthash);
- $hashfile = "$hashpath/$contenthash";
- -
- if (file_exists($hashfile)) {
- if (filesize($hashfile) !== $filesize) {
- - throw new file_pool_content_exception($contenthash);
- + throw new file_pool_content_exception($contenthash, $content, $sourcefilepath);
- }
- $newfile = false;
- @@ -1083,11 +1066,17 @@
- }
- $newfile = true;
- - file_put_contents($hashfile, $content);
- + if (!is_null($content)) {
- + file_put_contents($hashfile, $content);
- + } else {
- + if (!copy($pathname, $hashfile)) {
- + throw new file_exception('storedfilecannotread');
- + }
- + }
- if (filesize($hashfile) !== $filesize) {
- @unlink($hashfile);
- - throw new file_pool_content_exception($contenthash);
- + throw new file_pool_content_exception($contenthash, $content, $sourcefilepath);
- }
- chmod($hashfile, $this->filepermissions); // fix permissions if needed
- }
- Index: lang/en/error.php
- ===================================================================
- RCS file: /cvsroot/moodle/moodle/lang/en/error.php,v
- retrieving revision 1.58
- diff -u -r1.58 error.php
- --- lang/en/error.php 19 Nov 2010 03:40:45 -0000 1.58
- +++ lang/en/error.php 27 Nov 2010 12:00:31 -0000
- @@ -244,7 +244,7 @@
- $string['guestnorate'] = 'Guests are not allowed to rate entries';
- $string['guestsarenotallowed'] = 'The guest user is not allowed to do this';
- $string['hackdetected'] = 'Hack attack detected!';
- -$string['hashpoolproblem'] = 'Incorrect pool file content {$a}.';
- +$string['hashpoolproblem'] = 'Inconsistent data found in the file pool for hash {$a->hash} when trying to add a new file from {$a->source}.';
- $string['headersent'] = 'Headers already sent';
- $string['idnumbertaken'] = 'ID number is already used for another course';
- $string['importformatnotimplement'] = 'Sorry, importing this format is not yet implemented!';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement