| 195 | } |
| 196 | |
| 197 | bool DebGenerator::generateDataTar() const |
| 198 | { |
| 199 | std::string filename_data_tar = |
| 200 | this->WorkDir + "/data.tar" + this->CompressionSuffix; |
| 201 | cmGeneratedFileStream fileStream_data_tar; |
| 202 | fileStream_data_tar.Open(filename_data_tar, false, true); |
| 203 | if (!fileStream_data_tar) { |
| 204 | cmCPackLogger(cmCPackLog::LOG_ERROR, |
| 205 | "Error opening the file \"" |
| 206 | << filename_data_tar << "\" for writing" << std::endl); |
| 207 | return false; |
| 208 | } |
| 209 | cmArchiveWrite data_tar(fileStream_data_tar, this->TarCompressionType, |
| 210 | this->DebianArchiveType, this->CompressionLevel, |
| 211 | static_cast<int>(this->NumThreads)); |
| 212 | if (!data_tar.Open()) { |
| 213 | cmCPackLogger(cmCPackLog::LOG_ERROR, |
| 214 | "Error opening the archive \"" |
| 215 | << filename_data_tar |
| 216 | << "\", ERROR = " << data_tar.GetError() << std::endl); |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | // uid/gid should be the one of the root user, and this root user has |
| 221 | // always uid/gid equal to 0. |
| 222 | data_tar.SetUIDAndGID(0U, 0U); |
| 223 | data_tar.SetUNAMEAndGNAME("root", "root"); |
| 224 | |
| 225 | // now add all directories which have to be compressed |
| 226 | // collect all top level install dirs for that |
| 227 | // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would |
| 228 | // give /usr and /opt |
| 229 | size_t topLevelLength = this->WorkDir.length(); |
| 230 | cmCPackLogger(cmCPackLog::LOG_DEBUG, |
| 231 | "WDIR: \"" << this->WorkDir |
| 232 | << "\", length = " << topLevelLength << std::endl); |
| 233 | std::set<std::string> orderedFiles; |
| 234 | |
| 235 | // we have to reconstruct the parent folders as well |
| 236 | |
| 237 | for (std::string currentPath : this->PackageFiles) { |
| 238 | while (currentPath != this->WorkDir) { |
| 239 | // the last one IS WorkDir, but we do not want this one: |
| 240 | // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application |
| 241 | // should not add XXX/application |
| 242 | orderedFiles.insert(currentPath); |
| 243 | currentPath = cmSystemTools::GetFilenamePath(currentPath); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | for (std::string const& file : orderedFiles) { |
| 248 | cmCPackLogger(cmCPackLog::LOG_DEBUG, |
| 249 | "FILEIT: \"" << file << "\"" << std::endl); |
| 250 | std::string::size_type slashPos = file.find('/', topLevelLength + 1); |
| 251 | std::string relativeDir = |
| 252 | file.substr(topLevelLength, slashPos - topLevelLength); |
| 253 | cmCPackLogger(cmCPackLog::LOG_DEBUG, |
| 254 | "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl); |
no test coverage detected