| 219 | } |
| 220 | |
| 221 | int charset_transfer::transfer(bool recursive /* = true */) |
| 222 | { |
| 223 | if (check_params() == false) |
| 224 | return -1; |
| 225 | |
| 226 | if (from_charset_.equal(to_charset_, false)) |
| 227 | { |
| 228 | logger("to_charset_ is same as from_charset_(%s)", |
| 229 | from_charset_.c_str()); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | acl::scan_dir scan; |
| 234 | |
| 235 | if (scan.open(from_path_, recursive) == false) |
| 236 | { |
| 237 | logger_error("open dir %s error %s", from_path_.c_str(), |
| 238 | acl::last_serror()); |
| 239 | return -1; |
| 240 | } |
| 241 | |
| 242 | int count = 0; |
| 243 | const char* filename; |
| 244 | |
| 245 | while ((filename = scan.next_file(false)) != NULL) |
| 246 | { |
| 247 | acl::string from_filepath, to_filepath, to_path; |
| 248 | if (!get_filepath(scan, filename, from_filepath, |
| 249 | to_filepath, to_path)) |
| 250 | { |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | if (access(to_path.c_str(), 0) != 0 |
| 255 | && (acl_make_dirs(to_path.c_str(), 0755) == -1)) |
| 256 | { |
| 257 | logger_error("acl_make_dirs %s error %s", |
| 258 | to_path.c_str(), acl::last_serror()); |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | if (transfer(from_filepath, to_filepath)) |
| 263 | { |
| 264 | logger("transfer to %s OK!", to_filepath.c_str()); |
| 265 | count++; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return count; |
| 270 | } |
| 271 | |
| 272 | bool charset_transfer::transfer(const char* from_file, const char* to_file) |
| 273 | { |
no test coverage detected