summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-09-01 12:26:45 +0200
committerTor Egge <Tor.Egge@online.no>2023-09-01 12:26:45 +0200
commit65e4e2c97da15945bfd811b7d0dbb45538cb527b (patch)
tree3bcb63ee5ff46dd7e0efe8c82ea3aff4f05f0945 /vespalib
parentab93e397405999f3cee7c7dcde618e44e04ea712 (diff)
Remove FastOS_DirectoryScan
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/fastos/file_test.cpp10
-rw-r--r--vespalib/src/vespa/fastos/file.cpp7
-rw-r--r--vespalib/src/vespa/fastos/file.h102
-rw-r--r--vespalib/src/vespa/fastos/linux_file.cpp1
-rw-r--r--vespalib/src/vespa/fastos/unix_file.cpp111
-rw-r--r--vespalib/src/vespa/fastos/unix_file.h31
6 files changed, 3 insertions, 259 deletions
diff --git a/vespalib/src/tests/fastos/file_test.cpp b/vespalib/src/tests/fastos/file_test.cpp
index 99c7b858723..a9cec81d084 100644
--- a/vespalib/src/tests/fastos/file_test.cpp
+++ b/vespalib/src/tests/fastos/file_test.cpp
@@ -181,16 +181,6 @@ TEST(FileTest, ReadWriteTest) {
EXPECT_TRUE(std::filesystem::remove(std::filesystem::path(rwFilename)));
}
-TEST(FileTest, ScanDirectoryTest) {
- auto scanDir = std::make_unique<FastOS_DirectoryScan>(".");
- while (scanDir->ReadNext()) {
- const char *name = scanDir->GetName();
- bool isDirectory = scanDir->IsDirectory();
- bool isRegular = scanDir->IsRegular();
- fprintf(stderr, "%-30s %s\n", name, isDirectory ? "DIR" : (isRegular ? "FILE" : "UNKN"));
- }
-}
-
TEST(FileTest, ReadBufTest) {
FastOS_File file(roFilename.c_str());
char buffer[20];
diff --git a/vespalib/src/vespa/fastos/file.cpp b/vespalib/src/vespa/fastos/file.cpp
index 19a000296de..0c05c1ad894 100644
--- a/vespalib/src/vespa/fastos/file.cpp
+++ b/vespalib/src/vespa/fastos/file.cpp
@@ -306,10 +306,3 @@ FastOS_FileInterface::getLastErrorString()
void FastOS_FileInterface::dropFromCache() const
{
}
-
-FastOS_DirectoryScanInterface::FastOS_DirectoryScanInterface(const char *path)
- : _searchPath(path)
-{
-}
-
-FastOS_DirectoryScanInterface::~FastOS_DirectoryScanInterface() = default;
diff --git a/vespalib/src/vespa/fastos/file.h b/vespalib/src/vespa/fastos/file.h
index 079a2b610f1..cd7a22a02b2 100644
--- a/vespalib/src/vespa/fastos/file.h
+++ b/vespalib/src/vespa/fastos/file.h
@@ -2,8 +2,7 @@
//************************************************************************
/**
* @file
- * Class definitions for FastOS_File, FastOS_DirectoryScan and
- * FastOS_StatInfo.
+ * Class definitions for FastOS_File and FastOS_StatInfo.
*
* @author Div, Oivind H. Danielsen
*/
@@ -544,104 +543,6 @@ public:
vespalib::system_time _modifiedTime;
};
-
-/**
- * This class enumerates the contents of a given directory.
- *
- * Example:
- * @code
- * void Foo::Bar()
- * {
- * // Scan and print the contents of the directory '/usr/src/include'
- *
- * FastOS_DirectoryScan dirScan("/usr/src/include");
- * int numEntries = 0;
- *
- * while(dirScan.ReadNext())
- * {
- * const char *name = dirScan.GetName();
- * bool isDirectory = dirScan.IsDirectory();
- * bool isRegular = dirScan.IsRegular();
- *
- * printf("%-30s %s\n", name,
- * isDirectory ? "DIR" : (isRegular ? "FILE" : "UNKN"));
- *
- * numEntries++;
- * }
- *
- * printf("The directory contained %d entries.\n", numEntries);
- * }
- * @endcode
- */
-class FastOS_DirectoryScanInterface
-{
-protected:
- std::string _searchPath;
-
-public:
- FastOS_DirectoryScanInterface(const FastOS_DirectoryScanInterface&) = delete;
- FastOS_DirectoryScanInterface& operator= (const FastOS_DirectoryScanInterface&) = delete;
-
- /**
- * Constructor.
- *
- * @param path Path of the directory to be scanned. The path string
- * is copied internally.
- */
- FastOS_DirectoryScanInterface(const char *path);
-
- /**
- * Destructor.
- *
- * Frees operating system resources related to the directory scan.
- */
- virtual ~FastOS_DirectoryScanInterface();
-
- /**
- * Read the next entry in the directory scan. Failure indicates
- * that there are no more entries. If the call is successful,
- * attributes for the entry can be read with @ref IsDirectory(),
- * @ref IsRegular() and @ref GetName().
- *
- * @return Boolean success/failure
- */
- virtual bool ReadNext() = 0;
-
- /**
- * After a successful @ref ReadNext() this method is used to
- * determine if the entry is a directory entry or not. Calling this
- * method after an unsuccessful @ref ReadNext() or before
- * @ref ReadNext() is called for the first time, yields undefined
- * results.
- *
- * @return True if the entry is a directory, else false.
- */
- virtual bool IsDirectory() = 0;
-
-
- /**
- * After a successful @ref ReadNext() this method is used to
- * determine if the entry is a regular file entry or not. Calling
- * this method after an unsuccessful @ref ReadNext() or before
- * @ref ReadNext() is called for the first time, yields undefined
- * results.
- *
- * @return True if the entry is a regular file, else false.
- */
- virtual bool IsRegular() = 0;
-
- /**
- * After a successful @ref ReadNext() this method is used to
- * determine the name of the recently read directory entry. Calling
- * this method after an unsuccessful @ref ReadNext() or before
- * @ref ReadNext() is called for the first time, yields undefined
- * results.
- *
- * @return A pointer to the recently read directory entry.
- */
- virtual const char *GetName() = 0;
-};
-
#ifdef __linux__
#include <vespa/fastos/linux_file.h>
typedef FastOS_Linux_File FASTOS_PREFIX(File);
@@ -649,4 +550,3 @@ typedef FastOS_Linux_File FASTOS_PREFIX(File);
#include <vespa/fastos/unix_file.h>
typedef FastOS_UNIX_File FASTOS_PREFIX(File);
#endif
-typedef FastOS_UNIX_DirectoryScan FASTOS_PREFIX(DirectoryScan);
diff --git a/vespalib/src/vespa/fastos/linux_file.cpp b/vespalib/src/vespa/fastos/linux_file.cpp
index b8ee005517a..3344250838c 100644
--- a/vespalib/src/vespa/fastos/linux_file.cpp
+++ b/vespalib/src/vespa/fastos/linux_file.cpp
@@ -11,6 +11,7 @@
#include "file.h"
#include "file_rw_ops.h"
#include <sstream>
+#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
#include <cstdio>
diff --git a/vespalib/src/vespa/fastos/unix_file.cpp b/vespalib/src/vespa/fastos/unix_file.cpp
index 6d10338aec1..b9fe46e920d 100644
--- a/vespalib/src/vespa/fastos/unix_file.cpp
+++ b/vespalib/src/vespa/fastos/unix_file.cpp
@@ -368,114 +368,3 @@ FastOS_UNIX_File::count_open_files()
return 0;
#endif
}
-
-FastOS_UNIX_DirectoryScan::FastOS_UNIX_DirectoryScan(const char *searchPath)
- : FastOS_DirectoryScanInterface(searchPath),
- _statRun(false),
- _isDirectory(false),
- _isRegular(false),
- _statName(nullptr),
- _statFilenameP(nullptr),
- _dir(nullptr),
- _dp(nullptr)
-{
- _dir = opendir(searchPath);
-
- const int minimumLength = 512 + 1;
- const int defaultLength = 16384;
-
- int maxNameLength = FastOS_File::GetMaximumFilenameLength(searchPath);
- int maxPathLength = FastOS_File::GetMaximumPathLength(searchPath);
- int nameLength = maxNameLength + 1 + maxPathLength;
-
- if ((maxNameLength == -1) ||
- (maxPathLength == -1) ||
- (nameLength < minimumLength))
- {
- nameLength = defaultLength;
- }
-
- _statName = new char [nameLength + 1]; // Include null
-
- strcpy(_statName, searchPath);
- strcat(_statName, "/");
-
- _statFilenameP = &_statName[strlen(_statName)];
-}
-
-
-FastOS_UNIX_DirectoryScan::~FastOS_UNIX_DirectoryScan()
-{
- if (_dir != nullptr) {
- closedir(_dir);
- _dir = nullptr;
- }
- delete [] _statName;
-}
-
-
-bool
-FastOS_UNIX_DirectoryScan::ReadNext()
-{
- _statRun = false;
-
- if (_dir != nullptr) {
- _dp = readdir(_dir);
- return (_dp != nullptr);
- }
-
- return false;
-}
-
-
-void
-FastOS_UNIX_DirectoryScan::DoStat()
-{
- struct stat stbuf{};
-
- assert(_dp != nullptr);
-
- strcpy(_statFilenameP, _dp->d_name);
-
- if (lstat(_statName, &stbuf) == 0) {
- _isRegular = S_ISREG(stbuf.st_mode);
- _isDirectory = S_ISDIR(stbuf.st_mode);
- } else {
- printf("lstat failed for [%s]\n", _dp->d_name);
- _isRegular = false;
- _isDirectory = false;
- }
-
- _statRun = true;
-}
-
-
-bool
-FastOS_UNIX_DirectoryScan::IsDirectory()
-{
- if (!_statRun) {
- DoStat();
- }
-
- return _isDirectory;
-}
-
-
-bool
-FastOS_UNIX_DirectoryScan::IsRegular()
-{
- if (!_statRun) {
- DoStat();
- }
-
- return _isRegular;
-}
-
-
-const char *
-FastOS_UNIX_DirectoryScan::GetName()
-{
- assert(_dp != nullptr);
-
- return static_cast<const char *>(_dp->d_name);
-}
diff --git a/vespalib/src/vespa/fastos/unix_file.h b/vespalib/src/vespa/fastos/unix_file.h
index dad75dc561f..81e5de901a3 100644
--- a/vespalib/src/vespa/fastos/unix_file.h
+++ b/vespalib/src/vespa/fastos/unix_file.h
@@ -4,7 +4,7 @@
* @author Oivind H. Danielsen
* @date Creation date: 2000-01-18
* @file
-* Class definitions for FastOS_UNIX_File and FastOS_UNIX_DirectoryScan.
+* Class definitions for FastOS_UNIX_File
*****************************************************************************/
#pragma once
@@ -83,32 +83,3 @@ public:
static int64_t GetFreeDiskSpace (const char *path);
static int count_open_files();
};
-
-#include <dirent.h>
-/**
- * This is the generic UNIX implementation of @ref FastOS_DirectoryScan.
- */
-class FastOS_UNIX_DirectoryScan : public FastOS_DirectoryScanInterface
-{
-private:
- bool _statRun;
- bool _isDirectory;
- bool _isRegular;
- char *_statName;
- char *_statFilenameP;
-
- void DoStat();
-
-protected:
- DIR *_dir;
- struct dirent *_dp;
-
-public:
- FastOS_UNIX_DirectoryScan(const char *searchPath);
- ~FastOS_UNIX_DirectoryScan();
-
- bool ReadNext() override;
- bool IsDirectory() override;
- bool IsRegular() override;
- const char *GetName() override;
-};