Browse Source

Merge pull request #506 from trapexit/literal_glob

keep literal when glob fails
pull/509/head
trapexit 6 years ago
committed by GitHub
parent
commit
19a7d43b31
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/fs.cpp
  2. 3
      src/fs.hpp
  3. 53
      src/fs_glob.cpp
  4. 28
      src/fs_glob.hpp
  5. 1
      src/option_parser.cpp
  6. 1
      src/setxattr.cpp

26
src/fs.cpp

@ -18,7 +18,6 @@
#include <vector>
#include <fcntl.h>
#include <glob.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
@ -170,31 +169,6 @@ namespace fs
return (errno=ENOENT,-1);
}
void
glob(const vector<string> &patterns,
vector<string> &strs)
{
int flags;
size_t veclen;
glob_t gbuf = {0};
veclen = patterns.size();
if(veclen == 0)
return;
flags = 0;
glob(patterns[0].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND;
for(size_t i = 1; i < veclen; i++)
glob(patterns[i].c_str(),flags,NULL,&gbuf);
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
strs.push_back(gbuf.gl_pathv[i]);
globfree(&gbuf);
}
void
realpathize(vector<string> &strs)
{

3
src/fs.hpp

@ -53,9 +53,6 @@ namespace fs
const int fd,
string &basepath);
void glob(const vector<string> &patterns,
vector<string> &strs);
void realpathize(vector<string> &strs);
int getfl(const int fd);

53
src/fs_glob.cpp

@ -0,0 +1,53 @@
/*
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <glob.h>
#include <string>
#include <vector>
using std::string;
using std::vector;
namespace fs
{
void
glob(const vector<string> &patterns_,
vector<string> &strs_)
{
int flags;
size_t veclen;
glob_t gbuf = {0};
veclen = patterns_.size();
if(veclen == 0)
return;
flags = GLOB_NOCHECK;
::glob(patterns_[0].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND|GLOB_NOCHECK;
for(size_t i = 1; i < veclen; i++)
::glob(patterns_[i].c_str(),flags,NULL,&gbuf);
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
strs_.push_back(gbuf.gl_pathv[i]);
::globfree(&gbuf);
}
}

28
src/fs_glob.hpp

@ -0,0 +1,28 @@
/*
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <string>
#include <vector>
namespace fs
{
using std::string;
using std::vector;
void
glob(const vector<string> &patterns_,
vector<string> &strs_);
}

1
src/option_parser.cpp

@ -29,6 +29,7 @@
#include <iomanip>
#include "config.hpp"
#include "fs_glob.hpp"
#include "num.hpp"
#include "policy.hpp"
#include "str.hpp"

1
src/setxattr.cpp

@ -25,6 +25,7 @@
#include "config.hpp"
#include "errno.hpp"
#include "fs_base_setxattr.hpp"
#include "fs_glob.hpp"
#include "fs_path.hpp"
#include "num.hpp"
#include "rv.hpp"

Loading…
Cancel
Save