Welcome to mirror list, hosted at ThFree Co, Russian Federation.

platform_unix_impl.cpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d16291c1e76783021d60380c72d30166313d4d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "platform.hpp"
#include "platform_unix_impl.hpp"

#include "../base/logging.hpp"
#include "../base/regexp.hpp"

#include <dirent.h>
#include <sys/stat.h>

#if defined(OMIM_OS_MAC) || defined(OMIM_OS_IPHONE)
  #include <sys/mount.h>
#else
  #include <sys/vfs.h>
#endif


bool Platform::IsFileExistsByFullPath(string const & filePath)
{
  struct stat s;
  return stat(filePath.c_str(), &s) == 0;
}

bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size)
{
  struct stat s;
  if (stat(filePath.c_str(), &s) == 0)
  {
    size = s.st_size;
    return true;
  }
  else return false;
}

Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) const
{
  struct statfs st;
  int const ret = statfs(m_writableDir.c_str(), &st);

  LOG(LDEBUG, ("statfs return = ", ret,
               "; block size = ", st.f_bsize,
               "; blocks available = ", st.f_bavail));

  if (ret != 0)
    return STORAGE_DISCONNECTED;

  /// @todo May be add additional storage space.
  if (st.f_bsize * st.f_bavail < neededSize)
    return NOT_ENOUGH_SPACE;

  return STORAGE_OK;
}

namespace pl
{

void EnumerateFilesByRegExp(string const & directory, string const & regexp,
                            vector<string> & res)
{
  DIR * dir;
  struct dirent * entry;
  if ((dir = opendir(directory.c_str())) == NULL)
    return;

  regexp::RegExpT exp;
  regexp::Create(regexp, exp);

  while ((entry = readdir(dir)) != 0)
  {
    string const name(entry->d_name);
    if (regexp::IsExist(name, exp))
      res.push_back(name);
  }

  closedir(dir);
}

}