X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/wikimedia/cdb/src/Writer/DBA.php diff --git a/vendor/wikimedia/cdb/src/Writer/DBA.php b/vendor/wikimedia/cdb/src/Writer/DBA.php new file mode 100644 index 00000000..20d0adfb --- /dev/null +++ b/vendor/wikimedia/cdb/src/Writer/DBA.php @@ -0,0 +1,64 @@ +realFileName = $fileName; + $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); + $this->handle = dba_open( $this->tmpFileName, 'n', 'cdb_make' ); + if ( !$this->handle ) { + throw new Exception( 'Unable to open CDB file for write "' . $fileName . '"' ); + } + } + + public function set( $key, $value ) { + return dba_insert( $key, $value, $this->handle ); + } + + /** + * @throws Exception + */ + public function close() { + if ( isset( $this->handle ) ) { + dba_close( $this->handle ); + } + if ( $this->isWindows() ) { + unlink( $this->realFileName ); + } + if ( !rename( $this->tmpFileName, $this->realFileName ) ) { + throw new Exception( 'Unable to move the new CDB file into place.' ); + } + unset( $this->handle ); + } +}