int cmd_ls_file_meta(const VSTRING& param) { int ret = TFS_SUCCESS; char appkey[257]; if (!g_use_meta) { TBSYS_LOG(WARN, "sorry, this commond is for name meta!!!"); } else { const char* file_path = expand_path(const_cast<string&>(param[0])); int size = param.size(); if (size > 1) { strncpy(appkey, param[1].c_str(), 256); appkey[256] = '\0'; } else { strcpy(appkey, app_key); } if (size > 2) { app_id = strtoll(param[2].c_str(), NULL, 10); } if (size > 3) { uid = strtoll(param[3].c_str(), NULL, 10); } RcClientImpl impl; ret = impl.initialize(rc_addr, appkey, app_ip); if (TFS_SUCCESS != ret) { TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret); } else { FileMetaInfo file_info; ret = impl.ls_file(app_id, uid, file_path, file_info); if (TFS_SUCCESS == ret) { if (file_info.name_.size() > 0) fprintf(stdout, "name:%s\n", file_info.name_.data()); fprintf(stdout, "pid %"PRI64_PREFIX"d id %"PRI64_PREFIX "d create_time %s modify_time %s size %"PRI64_PREFIX"d ver_no %d\n", file_info.pid_, file_info.id_, Func::time_to_str(file_info.create_time_).c_str(), Func::time_to_str(file_info.modify_time_).c_str(), file_info.size_, file_info.ver_no_); } } } return ret; }
int cmd_put_file_meta(const VSTRING& param) { int ret = TFS_SUCCESS; const char* local_file = expand_path(const_cast<string&>(param[0])); const char* file_path = expand_path(const_cast<string&>(param[1])); char appkey[257]; int size = param.size(); if (size > 2) { strncpy(appkey, param[2].c_str(), 256); appkey[256] = '\0'; } else { strcpy(appkey, app_key); } if (size > 3) { app_id = strtoll(param[3].c_str(), NULL, 10); } if (size > 4) { uid = strtoll(param[4].c_str(), NULL, 10); } RcClientImpl impl; ret = impl.initialize(rc_addr, appkey, app_ip); if (TFS_SUCCESS != ret) { TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret); } else { FILE* fp=fopen(local_file,"r"); if(fp == NULL) { TBSYS_LOG(WARN, "open local file failed. local_file: %s, ret: %p", local_file, fp); ret = TFS_ERROR; } else { // create file if not exist FileMetaInfo file_meta_info; ret = impl.ls_file(app_id, uid, file_path, file_meta_info); if (ret != TFS_SUCCESS) { ret = impl.create_file(uid, file_path); } if (ret != TFS_SUCCESS) { TBSYS_LOG(DEBUG, "create file failed. file_path: %s, ret: %d", file_path, ret); } else { int fd = impl.open(app_id, uid, file_path, RcClient::WRITE); if (fd < 0) { TBSYS_LOG(WARN, "open file path failed. file_path: %s, ret: %d", file_path, fd); ret = TFS_ERROR; } else { int64_t offset = 0; char buffer[MAX_READ_SIZE]; while (true) { int64_t rlen = fread(buffer,sizeof(char),MAX_READ_SIZE,fp); if (rlen <= 0) { break; } int64_t wlen = impl.pwrite(fd, buffer, rlen, offset); if (wlen != rlen) { TBSYS_LOG(ERROR, "write meta data failed. expect len: %"PRI64_PREFIX"d, return len: %"PRI64_PREFIX"d", rlen, wlen); ret = TFS_ERROR; break; } offset = -1; if (rlen < MAX_READ_SIZE) { break; } } impl.close(fd); } } fclose(fp); } } ToolUtil::print_info(ret, "put %s => %s", local_file, file_path); return ret; }