Permalink
Browse files

Clean up recovery of projects. Store file id separately for compile

commands. Otherwise we get corruption when the fileids are lost.
  • Loading branch information...
Andersbakken committed Oct 3, 2017
1 parent 5df12f6 commit 1e86821842320b0a079080437146074e9a58aa63
Showing with 37 additions and 25 deletions.
  1. +1 −1 CMakeLists.txt
  2. +5 −2 src/IndexParseData.h
  3. +1 −1 src/IndexerJob.cpp
  4. +8 −8 src/Project.cpp
  5. +3 −2 src/Project.h
  6. +19 −11 src/Server.cpp
View
@@ -3,7 +3,7 @@ project(rtags)
set(RTAGS_VERSION_MAJOR 2)
set(RTAGS_VERSION_MINOR 14)
set(RTAGS_VERSION_DATABASE 120)
set(RTAGS_VERSION_SOURCES_FILE 12)
set(RTAGS_VERSION_SOURCES_FILE 13)
set(RTAGS_VERSION ${RTAGS_VERSION_MAJOR}.${RTAGS_VERSION_MINOR}.${RTAGS_VERSION_DATABASE})
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
View
@@ -89,7 +89,7 @@ inline Serializer &operator<<(Serializer &s, const IndexParseData &data)
{
s << Sandbox::encoded(data.project) << static_cast<uint32_t>(data.compileCommands.size());
for (const auto &pair : data.compileCommands) {
s << Location::path(pair.first) << pair.second;
s << Location::path(pair.first) << pair.first << pair.second;
}
s << data.sources << Sandbox::encoded(data.environment);
return s;
@@ -104,7 +104,10 @@ inline Deserializer &operator>>(Deserializer &s, IndexParseData &data)
while (size-- > 0) {
Path file;
s >> file;
s >> data.compileCommands[Location::insertFile(file)];
uint32_t fileId;
s >> fileId;
Location::set(file, fileId);
s >> data.compileCommands[fileId];
}
s >> data.sources >> data.environment;
Sandbox::decode(data.environment);
View
@@ -225,7 +225,7 @@ String IndexerJob::dumpFlags(Flags<Flag> flags)
void IndexerJob::recalculatePriority()
{
#warning should consider current project to be of higher priority
// #warning should consider current project to be of higher priority
mCachedPriority = INT_MIN;
priority();
}
View
@@ -257,15 +257,11 @@ static void saveDependencies(DataFile &file, const Dependencies &dependencies)
}
Project::Project(const Path &path)
: mPath(path), mSourceFilePathBase(RTags::encodeSourceFilePath(Server::instance()->options().dataDir, path)),
: mPath(path), mProjectDataDir(RTags::encodeSourceFilePath(Server::instance()->options().dataDir, path)),
mJobCounter(0), mJobsStarted(0), mBytesWritten(0), mSaveDirty(false)
{
Path srcPath = mPath;
RTags::encodePath(srcPath);
const Server::Options &options = Server::instance()->options();
const Path tmp = options.dataDir + srcPath;
mProjectFilePath = tmp + "/project";
mSourcesFilePath = tmp + "/sources";
mProjectFilePath = mProjectDataDir + "project";
mSourcesFilePath = mProjectDataDir + "sources";
}
Project::~Project()
@@ -851,10 +847,14 @@ bool Project::save()
{
DataFile file(mSourcesFilePath, RTags::SourcesFileVersion);
if (!file.open(DataFile::Write)) {
error("Save error %s: %s", mProjectFilePath.constData(), file.error().constData());
error("Save error %s: %s", mSourcesFilePath.constData(), file.error().constData());
return false;
}
file << mIndexParseData;
if (!file.flush()) {
error("Save error %s: %s", mSourcesFilePath.constData(), file.error().constData());
return false;
}
}
{
DataFile file(mProjectFilePath, RTags::DatabaseVersion);
View
@@ -76,6 +76,7 @@ class Project : public std::enable_shared_from_this<Project>
std::shared_ptr<FileManager> fileManager() const { return mFileManager; }
Path path() const { return mPath; }
Path projectDataDir() const { return mProjectDataDir; }
bool match(const Match &match, bool *indexed = 0) const;
enum FileMapType {
@@ -406,7 +407,7 @@ class Project : public std::enable_shared_from_this<Project>
std::shared_ptr<FileMapScope> mFileMapScope;
const Path mPath, mSourceFilePathBase;
const Path mPath, mProjectDataDir;
Path mProjectFilePath, mSourcesFilePath;
Files mFiles;
@@ -470,7 +471,7 @@ inline void Project::releaseFileIds(const Set<uint32_t> &fileIds)
inline Path Project::sourceFilePath(uint32_t fileId, const char *type) const
{
return String::format<1024>("%s%d/%s", mSourceFilePathBase.constData(), fileId, type);
return String::format<1024>("%s%d/%s", mProjectDataDir.constData(), fileId, type);
}
#endif
View
@@ -185,10 +185,12 @@ bool Server::init(const Options &options)
{
Log l(LogLevel::Error, LogOutput::StdOut|LogOutput::TrailingNewLine);
l << "Running with" << mOptions.jobCount << "jobs, using args:"
<< String::join(mOptions.defaultArguments, ' ') << '\n';
l << "Includepaths:";
for (const auto &inc : mOptions.includePaths)
l << inc.toString();
<< String::join(mOptions.defaultArguments, ' ');
if (!mOptions.includePaths.isEmpty()) {
l << "\nIncludepaths:";
for (const auto &inc : mOptions.includePaths)
l << inc.toString();
}
}
if (mOptions.options & ClearProjects) {
@@ -332,7 +334,9 @@ std::shared_ptr<Project> Server::addProject(const Path &path)
std::shared_ptr<Project> &project = mProjects[path];
if (!project) {
project.reset(new Project(path));
project->init();
if (!project->init()) {
Path::rmdir(project->projectDataDir());
}
}
return project;
}
@@ -638,10 +642,12 @@ void Server::handleIndexMessage(const std::shared_ptr<IndexMessage> &message, co
conn->finish(ret ? 0 : 1);
if (ret) {
auto proj = addProject(data.project);
assert(proj);
proj->processParseData(std::move(data));
if (!currentProject())
setCurrentProject(proj);
if (proj) {
assert(proj);
proj->processParseData(std::move(data));
if (!currentProject())
setCurrentProject(proj);
}
}
}
@@ -2103,8 +2109,10 @@ bool Server::load()
}
for (auto &s : projects) {
auto p = addProject(s.first);
p->processParseData(std::move(s.second));
p->save();
if (p) {
p->processParseData(std::move(s.second));
p->save();
}
}
}
return true;

0 comments on commit 1e86821

Please sign in to comment.