| 239 | } |
| 240 | |
| 241 | bool http_servlet::saveFile(acl::websocket& in, const acl::string& filename, |
| 242 | long long len) |
| 243 | { |
| 244 | acl::string filepath, tmppath; |
| 245 | filepath << var_cfg_upload_path << "/" << filename; |
| 246 | tmppath << filepath << ".tmp"; |
| 247 | printf("%s, %s\n", tmppath.c_str(), filepath.c_str()); |
| 248 | |
| 249 | acl::ofstream fp; |
| 250 | if (fp.open_trunc(tmppath) == false) |
| 251 | { |
| 252 | printf("open_write %s error %s\r\n", |
| 253 | tmppath.c_str(), acl::last_serror()); |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | if (saveFile(in, fp, len) == false) |
| 258 | { |
| 259 | fp.remove(); |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | fp.close(); |
| 264 | if (fp.rename(tmppath, filepath) == false) |
| 265 | { |
| 266 | fp.remove(); |
| 267 | logger_error("rename from %s to %s error %s", |
| 268 | tmppath.c_str(), filepath.c_str(), acl::last_serror()); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | bool http_servlet::saveFile(acl::websocket& in, acl::ofstream& fp, |
| 276 | long long len) |
nothing calls this directly
no test coverage detected