summaryrefslogtreecommitdiff
path: root/src/fs/files.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-23 01:06:11 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-23 01:06:11 +0300
commit2b6106c41f3959d4deb8efc58c9055de0339959e (patch)
tree2ae271cd59997d4fe128e0173c0224e28417b34b /src/fs/files.cpp
parent76667ef0fa911fc8bf37df72896645dbfbbc0763 (diff)
downloadmv-2b6106c41f3959d4deb8efc58c9055de0339959e.tar.gz
mv-2b6106c41f3959d4deb8efc58c9055de0339959e.tar.bz2
mv-2b6106c41f3959d4deb8efc58c9055de0339959e.tar.xz
mv-2b6106c41f3959d4deb8efc58c9055de0339959e.zip
Impliment basic VirtFsDir for virtual fs based on directories.
Api similar to VirtFs. VirtFsDir unused for now.
Diffstat (limited to 'src/fs/files.cpp')
-rw-r--r--src/fs/files.cpp44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/fs/files.cpp b/src/fs/files.cpp
index 516283fe6..abb0ee956 100644
--- a/src/fs/files.cpp
+++ b/src/fs/files.cpp
@@ -30,7 +30,10 @@
#include "fs/virtlist.h"
#endif // defined(ANDROID) || defined(__native_client__)
+#include "utils/stringutils.h"
+
#include <dirent.h>
+#include <sys/stat.h>
#include "debug.h"
@@ -206,13 +209,8 @@ int Files::copyFile(const std::string &restrict srcName,
bool Files::existsLocal(const std::string &path)
{
- bool flg(false);
- std::fstream file;
- file.open(path.c_str(), std::ios::in);
- if (file.is_open())
- flg = true;
- file.close();
- return flg;
+ struct stat statbuf;
+ return stat(path.c_str(), &statbuf) == 0;
}
bool Files::loadTextFileLocal(const std::string &fileName,
@@ -266,3 +264,35 @@ void Files::deleteFilesInDirectory(std::string path)
closedir(dir);
}
}
+
+void Files::enumFiles(StringVect &files,
+ std::string path,
+ const bool skipSymlinks)
+{
+ if (findLast(path, "/") == false)
+ path += "/";
+ const struct dirent *next_file = nullptr;
+ DIR *const dir = opendir(path.c_str());
+
+ if (dir)
+ {
+ while ((next_file = readdir(dir)))
+ {
+ const std::string file = next_file->d_name;
+ if (file == "." || file == "..")
+ continue;
+ if (skipSymlinks == true)
+ {
+ struct stat statbuf;
+ if (lstat(path.c_str(), &statbuf) == 0 &&
+ S_ISLNK(statbuf.st_mode) != 0)
+ {
+ continue;
+ }
+ }
+ files.push_back(file);
+ }
+ closedir(dir);
+ }
+}
+