Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add md5 of ROS_PACKAGE_PATH to cache file names. #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/rospack/rospack.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ROSPACK_DECL Rosstackage
std::vector<std::string>& indented_deps,
bool no_recursion_on_wet=false);
std::string getCachePath();
std::string getCacheName();
bool readCache();
void writeCache();
FILE* validateCache();
Expand Down
28 changes: 27 additions & 1 deletion src/rospack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,32 @@ Rosstackage::gatherDepsFull(Stackage* stackage, bool direct,
dep_chain);
}

std::string
Rosstackage::getCacheName()
{
char *rpp = getenv("ROS_PACKAGE_PATH");
if(rpp == NULL) {
return cache_name_;
}

const unsigned int HASH_SIZE = 16;
char hash_result[HASH_SIZE];
memset(hash_result, 0, HASH_SIZE);

for(unsigned int i = 0; i < strlen(rpp); i++) {
hash_result[i % HASH_SIZE] ^= rpp[i];
}

// convert to hex for output
char out_buf[HASH_SIZE*2 + 1]; // 2 hex out bytes per byte + \0
for(unsigned int i = 0; i < HASH_SIZE; i++) {
// per step XX\0 - always overwriting the \0 from the step before
snprintf(out_buf + (2*i), 3, "%02X", hash_result[i]);
}

return cache_name_ + "_" + out_buf;
}

std::string
Rosstackage::getCachePath()
{
Expand Down Expand Up @@ -1937,7 +1963,7 @@ Rosstackage::getCachePath()
logWarn(std::string("cannot create rospack cache directory ") +
cache_path.string() + ": " + e.what());
}
cache_path /= cache_name_;
cache_path /= getCacheName();
return cache_path.string();
}

Expand Down