Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

utils.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "includes.h"
  2. void prepare_logdir()
  3. {
  4. spdlog::drop_all();
  5. #ifdef _WIN32
  6. system("if not exist logs mkdir logs");
  7. system("del /F /Q logs\\*");
  8. #else
  9. auto rv = system("mkdir -p logs");
  10. if (rv != 0)
  11. {
  12. throw std::runtime_error("Failed to mkdir -p logs");
  13. }
  14. rv = system("rm -f logs/*");
  15. if (rv != 0)
  16. {
  17. throw std::runtime_error("Failed to rm -f logs/*");
  18. }
  19. #endif
  20. }
  21. std::string file_contents(const std::string &filename)
  22. {
  23. std::ifstream ifs(filename);
  24. if (!ifs)
  25. {
  26. throw std::runtime_error("Failed open file ");
  27. }
  28. return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
  29. }
  30. std::size_t count_lines(const std::string &filename)
  31. {
  32. std::ifstream ifs(filename);
  33. if (!ifs)
  34. {
  35. throw std::runtime_error("Failed open file ");
  36. }
  37. std::string line;
  38. size_t counter = 0;
  39. while (std::getline(ifs, line))
  40. counter++;
  41. return counter;
  42. }
  43. std::size_t get_filesize(const std::string &filename)
  44. {
  45. std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
  46. if (!ifs)
  47. {
  48. throw std::runtime_error("Failed open file ");
  49. }
  50. return static_cast<std::size_t>(ifs.tellg());
  51. }
  52. // source: https://stackoverflow.com/a/2072890/192001
  53. bool ends_with(std::string const &value, std::string const &ending)
  54. {
  55. if (ending.size() > value.size())
  56. {
  57. return false;
  58. }
  59. return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
  60. }