Skip to content

Commit

Permalink
Clean up recovery of projects. Store file id separately for compile
Browse files Browse the repository at this point in the history
commands. Otherwise we get corruption when the fileids are lost.
  • Loading branch information
Andersbakken committed Oct 3, 2017
1 parent 5df12f6 commit 1e86821
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/IndexParseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/IndexerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
16 changes: 8 additions & 8 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
30 changes: 19 additions & 11 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1e86821

Please sign in to comment.