strigi/src/streams
filestreamopener.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include "config.h"
00022 #endif
00023
00024 #include <strigi/strigiconfig.h>
00025 #include "archivereader.h"
00026 #include "fileinputstream.h"
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029
00030 using namespace std;
00031 using namespace Strigi;
00032
00033 InputStream*
00034 FileStreamOpener::openStream(const string& url) {
00035 InputStream* stream = new FileInputStream(url.c_str());
00036 if (stream->status() != Ok) {
00037 delete stream;
00038 stream = 0;
00039 }
00040 return stream;
00041 }
00042 int
00043 FileStreamOpener::stat(const string& url, EntryInfo& e) {
00044 struct stat s;
00045 if (::stat(url.c_str(), &s) == -1) {
00046 return -1;
00047 }
00048 if (S_ISREG(s.st_mode)) {
00049 e.type = EntryInfo::File;
00050 } else if (S_ISDIR(s.st_mode)) {
00051 e.type = EntryInfo::Dir;
00052 } else {
00053 e.type = EntryInfo::Unknown;
00054 }
00055 e.size = s.st_size;
00056 e.mtime = s.st_mtime;
00057 size_t p = url.rfind('/');
00058 if (p == string::npos) {
00059 e.filename = url;
00060 } else {
00061 e.filename = url.substr(p+1);
00062 }
00063
00064 return 0;
00065 }