/** * @brief Write this object in its serialized form to the git repository * given at creation time. */ public function write() { $sha1 = Git::sha1Hex($this->name); $path = sprintf('%s/objects/%s/%s', $this->repo->dir, substr($sha1, 0, 2), substr($sha1, 2)); if (file_exists($path)) { return false; } $dir = dirname($path); if (!is_dir($dir)) { mkdir(dirname($path), 0770); } $file = fopen($path, 'ab'); $file = stream_filter_append($file, "Gz.compress"); flock($file, LOCK_EX); ftruncate($file, 0); $data = $this->serialize(); $data = Git::getTypeName($this->type) . ' ' . strlen($data) . "" . $data; fwrite($file, gzcompress($data)); fclose($file); return true; }