• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.97
/pol-core/clib/fileutil.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6

7
#include "fileutil.h"
8
#include "Header_Windows.h"
9

10
#include <filesystem>
11
#include <limits.h>
12
#include <sys/stat.h>
13

14
#ifdef LINUX
15
#include <unistd.h>
16
#else
17
#include <direct.h>
18
#include <io.h>
19
#endif
20

21

22
namespace Pol::Clib
23
{
24
std::string normalized_dir_form( const std::string& istr )
24,457✔
25
{
26
  std::string str = istr;
24,457✔
27

28
  {
29
    std::string::size_type bslashpos;
30
    while ( std::string::npos != ( bslashpos = str.find( '\\' ) ) )
24,457✔
31
    {
32
      str.replace( bslashpos, 1, 1, '/' );
×
33
    }
34
  }
35

36
  if ( str.empty() )
24,457✔
37
  {
38
    return "/";
×
39
  }
40
  if ( str[str.size() - 1] == '/' || str[str.size() - 1] == '\\' )
24,457✔
41
  {
42
    return str;
8,649✔
43
  }
44

45
  return str + "/";
15,808✔
46
}
24,457✔
47

48
bool IsDirectory( const char* dir )
18✔
49
{
50
  std::string sdir( dir );
18✔
51
  if ( sdir[sdir.length() - 1] == '/' )
18✔
52
    sdir = sdir.erase( sdir.length() - 1, 1 );
18✔
53
  struct stat st;
54
  if ( stat( sdir.c_str(), &st ) )
18✔
55
    return false;
×
56
  return ( st.st_mode & S_IFDIR ? true : false );
18✔
57
}
18✔
58

59
void MakeDirectory( const char* dir )
5✔
60
{
61
#if defined( __unix__ ) || defined( __APPLE__ )
62
  mkdir( dir, 0777 );
5✔
63
#else
64
  mkdir( dir );
65
#endif
66
}
5✔
67

68
int strip_one( std::string& direc )
1,989✔
69
{
70
  std::string::size_type pos = direc.find_last_of( "\\/" );
1,989✔
71
  if ( pos == std::string::npos )
1,989✔
72
    return -1;
×
73
  if ( pos >= 1 && direc[pos - 1] == ':' )  // at "C:\"
1,989✔
74
    return -1;
×
75
  direc = direc.substr( 0, pos );
1,989✔
76
  return 0;
1,989✔
77
}
78

79
int make_dir( const char* dir )
8✔
80
{
81
  if ( access( dir, 0 ) )
8✔
82
  {
83
#ifdef _WIN32
84
    if ( CreateDirectory( dir, nullptr ) )  // why is windows too good for POSIX?
85
#else
86
    if ( mkdir( dir, 0777 ) == 0 )
8✔
87
#endif
88
    {
89
      return 0; /* made it okay */
4✔
90
    }
91

92
    // if didn't make it,
93
    std::string parent_dir = dir;
4✔
94
    if ( strip_one( parent_dir ) )
4✔
NEW
95
      return -1;
×
96
    if ( make_dir( parent_dir.c_str() ) )
4✔
NEW
97
      return -1;
×
98
#ifdef _WIN32
99
    if ( CreateDirectory( dir, nullptr ) )
100
      return 0;
101
#else
102
    if ( mkdir( dir, 0777 ) == 0 )
4✔
103
      return 0;
2✔
104
#endif
105
    // this test is mostly for the case where the path is in normalized form
106
    if ( access( dir, 0 ) == 0 )
2✔
107
      return 0;
2✔
NEW
108
    return -1;
×
109
  }
4✔
110
  return 0;
×
111
}
112

113
bool FileExists( const char* filename )
12,268✔
114
{
115
  return ( access( filename, 0 ) == 0 );
12,268✔
116
}
117
bool FileExists( const std::string& filename )
3,360✔
118
{
119
  return ( access( filename.c_str(), 0 ) == 0 );
3,360✔
120
}
121

122
int filesize( const char* fname )
682✔
123
{
124
  struct stat st;
125
  if ( stat( fname, &st ) )
682✔
126
    return 0;
×
127
  return st.st_size;
682✔
128
}
129

130
unsigned int GetFileTimestamp( const char* fname )
4,964✔
131
{
132
  struct stat st;
133
  if ( stat( fname, &st ) )
4,964✔
134
    return 0;
2,295✔
135
  return (unsigned int)st.st_mtime;
2,669✔
136
}
137

138
void RemoveFile( const std::string& fname )
131✔
139
{
140
  unlink( fname.c_str() );
131✔
141
}
131✔
142

143
std::string FullPath( const char* filename )
9,466✔
144
{
145
#if defined( __unix__ ) || defined( __APPLE__ )
146
  char tmp[PATH_MAX];
147
  if ( realpath( filename, tmp ) )
9,466✔
148
    return tmp;
9,459✔
149
  return "";
7✔
150
#else
151
  char p[1025];
152
  _fullpath( p, filename, sizeof p );
153
  return p;
154
#endif
155
}
156

157
std::string GetTrueName( const char* filename )
×
158
{
159
  std::error_code ec;
×
160
  auto canonical = std::filesystem::canonical( filename, ec );
×
161
  if ( ec )
×
162
    return filename;
×
NEW
163
  return canonical.filename().string();
×
164
}
×
165

166
std::string GetFilePart( const char* filename )
×
167
{
168
  return std::filesystem::path( filename ).filename().string();
×
169
}
170
}  // namespace Pol::Clib
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc