open-source-search-engine/Dir.h
Matt Wells c669f8c138 fix file descriptor leak in Dir class.
try to fix core from Thread getting SIGALRM.
try to set NOFILES to 1024 at startup in case
more are allowed.
2013-11-19 13:41:56 -08:00

56 lines
1.2 KiB
C++

#ifndef _DIR_H
#define _DIR_H
#include <sys/types.h> // for opendir
#include <dirent.h> // for opendir
#include "File.h" // for File::getFileSize()
class Dir {
public:
bool set ( char *dirName );
bool set ( char *d1 , char *d2 );
void reset ( );
bool open ( );
bool close ( );
void rewind ( ); // rewind to get the first filename
bool cleanOut ( ); // remove all files/dir in directory
bool create ( ); // create the directory
char *getNextFilename ( char *pattern = NULL );
// . calls getNextFilename and returns number of files matching the
// pattern
int getNumFiles ( char *pattern = NULL );
// . does not yet support recursion
long long getUsedSpace ( );
char *getNewFilename ( char *pattern ) ;
long long getNewId ( char *pattern ) ;
long long getFileId ( char *filename ) ;
char *getDir ( ) { return m_dirname; };
char *getDirName ( ) { return m_dirname; };
char *getDirname ( ) { return m_dirname; };
char *getFullName ( char *filename ); // prepends path
Dir ( );
~Dir ( );
private:
char *m_dirname;
DIR *m_dir;
bool m_needsClose;
};
#endif