| @@ 69-92 (lines=24) @@ | ||
| 66 | * |
|
| 67 | * @return bool |
|
| 68 | */ |
|
| 69 | public function write($path, $contents, Config $config) |
|
| 70 | { |
|
| 71 | $tmpfname = $this->writeTempFile($contents); |
|
| 72 | ||
| 73 | try { |
|
| 74 | $response = $this->normalizeResponse( |
|
| 75 | Cosapi::upload($this->getBucket(), $tmpfname, $path) |
|
| 76 | ); |
|
| 77 | ||
| 78 | $this->deleteTempFile($tmpfname); |
|
| 79 | ||
| 80 | $this->setContentType($path, $contents); |
|
| 81 | } catch (RuntimeException $exception) { |
|
| 82 | $this->deleteTempFile($tmpfname); |
|
| 83 | ||
| 84 | if ($exception->getCode() == -4018) { |
|
| 85 | return $this->getMetadata($path); |
|
| 86 | } |
|
| 87 | ||
| 88 | throw $exception; |
|
| 89 | } |
|
| 90 | ||
| 91 | return $response; |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * @param string $path |
|
| @@ 129-152 (lines=24) @@ | ||
| 126 | * |
|
| 127 | * @return bool |
|
| 128 | */ |
|
| 129 | public function update($path, $contents, Config $config) |
|
| 130 | { |
|
| 131 | $tmpfname = $this->writeTempFile($contents); |
|
| 132 | ||
| 133 | try { |
|
| 134 | $response = $this->normalizeResponse( |
|
| 135 | Cosapi::upload($this->getBucket(), $tmpfname, $path, null, null, 0) |
|
| 136 | ); |
|
| 137 | ||
| 138 | $this->deleteTempFile($tmpfname); |
|
| 139 | ||
| 140 | $this->setContentType($path, $contents); |
|
| 141 | } catch (RuntimeException $exception) { |
|
| 142 | $this->deleteTempFile($tmpfname); |
|
| 143 | ||
| 144 | if ($exception->getCode() == -4018) { |
|
| 145 | return $this->getMetadata($path); |
|
| 146 | } |
|
| 147 | ||
| 148 | throw $exception; |
|
| 149 | } |
|
| 150 | ||
| 151 | return $response; |
|
| 152 | } |
|
| 153 | ||
| 154 | /** |
|
| 155 | * @param string $path |
|