DCStatus DataCleaner::scan_features(const char* path, int dir_id) { int image_num = this->images_[dir_id].size(); int data_size = this->dim_; vector<string> images = this->images_[dir_id]; for(int i = 0; i < image_num ; i++ ) { string temp_file_path(path); temp_file_path +='/'; temp_file_path += images[i].c_str(); temp_file_path.erase(temp_file_path.end()-3, temp_file_path.end()); temp_file_path +="txt"; FILE *feature_fp; errno = 0; if ((feature_fp = fopen(temp_file_path.c_str(), "r")) == NULL) { cout<<"DataCleaner::scan_features: open file failed : "<<errno<<endl; if (errno == 2) cout<<"No file : "<<temp_file_path<<endl; return DC_FAILED; } float* feature_buf = (float*)malloc(sizeof(float)*data_size); for(int j = 0; j< data_size; j++) { fscanf(feature_fp, "%f", &feature_buf[j]); } fclose(feature_fp); this->image_features_[dir_id].push_back(new ImgFeature(this->dim_, (float*)feature_buf)); } return DC_SUCCESS; }
DCStatus DataCleaner::scan_features_binary(const char* path, int dir_id) { DIR *dp; struct dirent *d_info; struct stat d_stat; int feature_fd; if((dp = opendir(path)) == NULL) { cout<<"DataCleaner::scan_features: Open file failed"<<endl; return DC_FAILED; } while((d_info = readdir(dp)) != 0) { if (!strcmp(d_info->d_name, ".") || (!strcmp(d_info->d_name, ".."))) continue; string temp_file_path(path); temp_file_path +='/'; temp_file_path += d_info->d_name; if (lstat(temp_file_path.c_str(), &d_stat) < 0) { cout<<"DataCleaner::scan_features: lstat file failed"<<endl; return DC_FAILED; } if (S_ISREG(d_stat.st_mode)) { if ((feature_fd = open(temp_file_path.c_str(), O_RDONLY)) == -1) { cout<<"DataCleaner::scan_features: open file failed"<<endl; return DC_FAILED; } size_t data_size = sizeof(float)*this->dim_; void* feature_buf = malloc(data_size); ssize_t nread; while (data_size > 0) { nread = read(feature_fd, feature_buf, data_size); if (nread < 0) { cout<<"DataCleaner::scan_features:read file failed"<<endl; return DC_FAILED; } else if (nread == 0) { if (data_size > 0) { cout<<"DataCleaner::scan_features:wrong data structure"<<endl; return DC_FAILED; } } else { data_size -= nread; } } this->image_features_[dir_id].push_back(new ImgFeature(this->dim_, (float*)feature_buf)); } else { cout<<"DataCleaner::scan_features: wrong file type"<<endl; return DC_FAILED; } return DC_SUCCESS; } }
BaseLog* GitCommitLog::generateLog(std::string dir) { //get working directory char cwd_buff[1024]; if(getcwd(cwd_buff, 1024) != cwd_buff) { return 0; } //does directory have a .git ? std::string gitdir = dir + std::string("/.git"); struct stat dirinfo; int stat_rc = stat(gitdir.c_str(), &dirinfo); if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR)) { return 0; } std::string command = getLogCommand(); //create temp file char cmd_buff[2048]; char logfile_buff[1024]; #ifdef _WIN32 DWORD tmplen = GetTempPath(0, L""); if(tmplen == 0) return 0; std::vector<TCHAR> temp(tmplen+1); tmplen = GetTempPath(static_cast<DWORD>(temp.size()), &temp[0]); if(tmplen == 0 || tmplen >= temp.size()) return 0; std::string temp_file_path(temp.begin(), temp.begin() + static_cast<std::size_t>(tmplen)); temp_file_path += "gource.tmp"; sprintf(logfile_buff, "%s", temp_file_path.c_str()); #else uid_t myuid = getuid(); sprintf(logfile_buff, "/tmp/gource-%d.tmp", myuid); #endif sprintf(cmd_buff, "%s > %s", command.c_str(), logfile_buff); temp_file = std::string(logfile_buff); if(chdir(dir.c_str()) != 0) { return 0; } int command_rc = system(cmd_buff); if(command_rc != 0) { return 0; } // check for new-enough Git version // if %aN does not appear to be supported try %an std::ifstream in(logfile_buff); char firstBytes[9]; in.read(firstBytes, 8); in.close(); firstBytes[8] = '\0'; if(!strcmp(firstBytes, "user:%aN")) { char *pos = strstr(cmd_buff, "%aN"); pos[2] = 'n'; command_rc = system(cmd_buff); } //change back to original directoy chdir(cwd_buff); if(command_rc != 0) { return 0; } BaseLog* seeklog = new SeekLog(temp_file); return seeklog; }