Skip to content

Commit 6e51b16

Browse files
authored
replace boost filesystem exists (#5907)
* replace boost filesystem exists * fix clang-tidy errors * revert some changes * fix some typos * address review changes * address more review changes * Review changes
1 parent 6711098 commit 6e51b16

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

io/src/ifs_io.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
#include <cstring>
4444
#include <cerrno>
45-
#include <boost/filesystem.hpp> // for exists
4645
#include <boost/iostreams/device/mapped_file.hpp> // for mapped_file_source
4746

4847
///////////////////////////////////////////////////////////////////////////////////////////
@@ -60,15 +59,22 @@ pcl::IFSReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
6059
//cloud.is_dense = true;
6160

6261
std::uint32_t nr_points = 0;
62+
63+
if (file_name.empty ())
64+
{
65+
PCL_ERROR ("[pcl::IFSReader::readHeader] No file name given!\n");
66+
return (-1);
67+
}
68+
6369
std::ifstream fs;
70+
fs.open (file_name.c_str (), std::ios::binary);
6471

65-
if (file_name.empty() || !boost::filesystem::exists (file_name))
72+
if (!fs.good ())
6673
{
6774
PCL_ERROR ("[pcl::IFSReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
6875
return (-1);
6976
}
7077

71-
fs.open (file_name.c_str (), std::ios::binary);
7278
if (!fs.is_open () || fs.fail ())
7379
{
7480
PCL_ERROR ("[pcl::IFSReader::readHeader] Could not open file '%s'! Error : %s\n", file_name.c_str (), strerror(errno));

io/src/obj_io.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,20 @@ int
146146
pcl::MTLReader::read (const std::string& obj_file_name,
147147
const std::string& mtl_file_name)
148148
{
149-
if (obj_file_name.empty() || !boost::filesystem::exists (obj_file_name))
149+
if (obj_file_name.empty ())
150+
{
151+
PCL_ERROR ("[pcl::MTLReader::read] No OBJ file name given!\n");
152+
return (-1);
153+
}
154+
155+
if (!boost::filesystem::exists (obj_file_name))
150156
{
151157
PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'!\n",
152158
obj_file_name.c_str ());
153159
return (-1);
154160
}
155161

156-
if (mtl_file_name.empty())
162+
if (mtl_file_name.empty ())
157163
{
158164
PCL_ERROR ("[pcl::MTLReader::read] MTL file name is empty!\n");
159165
return (-1);
@@ -168,14 +174,23 @@ pcl::MTLReader::read (const std::string& obj_file_name,
168174
int
169175
pcl::MTLReader::read (const std::string& mtl_file_path)
170176
{
171-
if (mtl_file_path.empty() || !boost::filesystem::exists (mtl_file_path))
177+
if (mtl_file_path.empty ())
172178
{
173-
PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'.\n", mtl_file_path.c_str ());
179+
PCL_ERROR ("[pcl::MTLReader::read] No file name given!\n");
174180
return (-1);
175181
}
176182

183+
// Open file in binary mode to avoid problem of
184+
// std::getline() corrupting the result of ifstream::tellg()
177185
std::ifstream mtl_file;
178186
mtl_file.open (mtl_file_path.c_str (), std::ios::binary);
187+
188+
if (!mtl_file.good ())
189+
{
190+
PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'.\n", mtl_file_path.c_str ());
191+
return (-1);
192+
}
193+
179194
if (!mtl_file.is_open () || mtl_file.fail ())
180195
{
181196
PCL_ERROR ("[pcl::MTLReader::read] Could not open file '%s'! Error : %s\n",
@@ -340,18 +355,25 @@ pcl::OBJReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
340355
data_type = 0;
341356
data_idx = offset;
342357

343-
std::ifstream fs;
344358
std::string line;
345359

346-
if (file_name.empty() || !boost::filesystem::exists (file_name))
360+
if (file_name.empty ())
347361
{
348-
PCL_ERROR ("[pcl::OBJReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
362+
PCL_ERROR ("[pcl::OBJReader::readHeader] No file name given!\n");
349363
return (-1);
350364
}
351365

352366
// Open file in binary mode to avoid problem of
353367
// std::getline() corrupting the result of ifstream::tellg()
368+
std::ifstream fs;
354369
fs.open (file_name.c_str (), std::ios::binary);
370+
371+
if (!fs.good ())
372+
{
373+
PCL_ERROR ("[pcl::OBJReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
374+
return (-1);
375+
}
376+
355377
if (!fs.is_open () || fs.fail ())
356378
{
357379
PCL_ERROR ("[pcl::OBJReader::readHeader] Could not open file '%s'! Error : %s\n", file_name.c_str (), strerror(errno));

io/src/pcd_io.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,23 @@ pcl::PCDReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
385385
Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
386386
int &pcd_version, int &data_type, unsigned int &data_idx, const int offset)
387387
{
388-
if (file_name.empty() || !boost::filesystem::exists (file_name))
388+
if (file_name.empty ())
389389
{
390-
PCL_ERROR ("[pcl::PCDReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
390+
PCL_ERROR ("[pcl::PCDReader::readHeader] No file name given!\n");
391391
return (-1);
392392
}
393393

394394
// Open file in binary mode to avoid problem of
395395
// std::getline() corrupting the result of ifstream::tellg()
396396
std::ifstream fs;
397397
fs.open (file_name.c_str (), std::ios::binary);
398+
399+
if (!fs.good ())
400+
{
401+
PCL_ERROR ("[pcl::PCDReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
402+
return (-1);
403+
}
404+
398405
if (!fs.is_open () || fs.fail ())
399406
{
400407
PCL_ERROR ("[pcl::PCDReader::readHeader] Could not open file '%s'! Error : %s\n", file_name.c_str (), strerror (errno));
@@ -664,7 +671,13 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
664671
pcl::console::TicToc tt;
665672
tt.tic ();
666673

667-
if (file_name.empty() || !boost::filesystem::exists (file_name))
674+
if (file_name.empty ())
675+
{
676+
PCL_ERROR ("[pcl::PCDReader::read] No file name given!\n");
677+
return (-1);
678+
}
679+
680+
if (!boost::filesystem::exists (file_name))
668681
{
669682
PCL_ERROR ("[pcl::PCDReader::read] Could not find file '%s'.\n", file_name.c_str ());
670683
return (-1);

0 commit comments

Comments
 (0)