X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLinkDB.php;h=15fadbc3a6baa67e552517b429635aa5f0c79dd1;hb=2e28269baed195d58bbe169841eed176b171db76;hp=8473350555e3b8abfdba1a4bd995c9d1da249613;hpb=c580024cfbe5f0d290b09157b9665d1b4131d7f4;p=github%2Fshaarli%2FShaarli.git diff --git a/application/LinkDB.php b/application/LinkDB.php index 84733505..15fadbc3 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@ -212,11 +212,7 @@ You use the community supported version of the original Shaarli project, by Seba $this->_links[$link['linkdate']] = $link; // Write database to disk - // TODO: raise an exception if the file is not write-able - file_put_contents( - $this->_datastore, - self::$phpPrefix.base64_encode(gzdeflate(serialize($this->_links))).self::$phpSuffix - ); + $this->writeDB(); } /** @@ -267,6 +263,28 @@ You use the community supported version of the original Shaarli project, by Seba } } + /** + * Saves the database from memory to disk + * + * @throws IOException the datastore is not writable + */ + private function writeDB() + { + if (is_file($this->_datastore) && !is_writeable($this->_datastore)) { + // The datastore exists but is not writeable + throw new IOException($this->_datastore); + } else if (!is_file($this->_datastore) && !is_writeable(dirname($this->_datastore))) { + // The datastore does not exist and its parent directory is not writeable + throw new IOException(dirname($this->_datastore)); + } + + file_put_contents( + $this->_datastore, + self::$phpPrefix.base64_encode(gzdeflate(serialize($this->_links))).self::$phpSuffix + ); + + } + /** * Saves the database from memory to disk * @@ -278,10 +296,9 @@ You use the community supported version of the original Shaarli project, by Seba // TODO: raise an Exception instead die('You are not authorized to change the database.'); } - file_put_contents( - $this->_datastore, - self::$phpPrefix.base64_encode(gzdeflate(serialize($this->_links))).self::$phpSuffix - ); + + $this->writeDB(); + invalidateCaches($pageCacheDir); }