CodeCompass

Форк
0
/
parsercontext.cpp 
81 строка · 2.0 Кб
1
#include <fstream>
2

3
#include <boost/filesystem.hpp>
4

5
#include <model/file.h>
6
#include <model/file-odb.hxx>
7

8
#include <util/hash.h>
9
#include <util/odbtransaction.h>
10

11
#include <parser/parsercontext.h>
12
#include <parser/sourcemanager.h>
13

14
namespace po = boost::program_options;
15

16
namespace cc
17
{
18
namespace parser
19
{
20

21
ParserContext::ParserContext(
22
  std::shared_ptr<odb::database> db_,
23
  SourceManager& srcMgr_,
24
  std::string& compassRoot_,
25
  po::variables_map& options_) :
26
    db(db_),
27
    srcMgr(srcMgr_),
28
    compassRoot(compassRoot_),
29
    options(options_)
30
{
31
  std::unordered_map<std::string, std::string> fileHashes;
32

33
  (util::OdbTransaction(this->db))([&]
34
   {
35
     // Fetch directory and binary type files from SourceManager
36
     auto func = [](model::FilePtr item)
37
     {
38
       return item->type != model::File::DIRECTORY_TYPE &&
39
              item->type != model::File::BINARY_TYPE;
40
     };
41
     std::vector<model::FilePtr> files = this->srcMgr.getFiles(func);
42

43
     for (model::FilePtr file : files)
44
     {
45
       if (boost::filesystem::exists(file->path))
46
       {
47
         if (!fileStatus.count(file->path))
48
         {
49
           model::FileContentPtr content = file->content.load();
50
           if (!content)
51
             continue;
52

53
           fileHashes[file->path] = content->hash;
54

55
           std::ifstream fileStream(file->path);
56
           std::string fileContent(
57
             std::istreambuf_iterator<char>{fileStream},
58
             std::istreambuf_iterator<char>{});
59
           fileStream.close();
60

61
           if (content->hash != util::sha1Hash(fileContent))
62
           {
63
             this->fileStatus.emplace(
64
               file->path, cc::parser::IncrementalStatus::MODIFIED);
65
             LOG(debug) << "File modified: " << file->path;
66
           }
67
         }
68
       }
69
       else
70
       {
71
         fileStatus.emplace(
72
           file->path, cc::parser::IncrementalStatus::DELETED);
73
         LOG(debug) << "File deleted: " << file->path;
74
       }
75
     }
76

77
     // TODO: detect ADDED files
78
   });
79
}
80
}
81
}
82

83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.