IBR-DTN  1.0.0
FATFile.cpp
Go to the documentation of this file.
1 /*
2  * FATFile.h
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: David Goltzsche <goltzsch@ibr.cs.tu-bs.de>
7  * Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Created on: Sep 23, 2013
22  */
23 
24 #include "io/FATFile.h"
25 #include "io/FatImageReader.h"
26 #include <ibrcommon/Logger.h>
27 
28 namespace io
29 {
30  const std::string FATFile::TAG = "FatFile";
31 
33  : ibrcommon::File("/", DT_DIR), _reader(reader)
34  {
35  }
36 
37  FATFile::FATFile(const FatImageReader &reader, const std::string &file_path)
38  : ibrcommon::File(file_path), _reader(reader)
39  {
40  update();
41  }
42 
44  {
45  }
46 
47  int FATFile::getFiles(std::list<FATFile> &files) const
48  {
49  try {
50  _reader.list(*this, files);
51  } catch (const FatImageReader::FatImageException &e) {
52  return e.getErrorCode();
53  }
54  IBRCOMMON_LOGGER_TAG(TAG,notice) << "getFile returning " << files.size() << " files" << IBRCOMMON_LOGGER_ENDL;
55  return 0;
56  }
57 
58  int FATFile::remove(bool recursive)
59  {
60  // deletion is not supported
61  return 1;
62  }
63 
64  FATFile FATFile::get(const std::string &filename) const
65  {
66  const ibrcommon::File child = ibrcommon::File::get(filename);
67  return FATFile(_reader, child.getPath());
68  }
69 
71  {
72  const ibrcommon::File parent = ibrcommon::File::getParent();
73  return FATFile(_reader, parent.getPath());
74  }
75 
76  bool FATFile::exists() const
77  {
78  return _reader.exists(*this);
79  }
80 
82  {
83  if (_reader.isDirectory(*this)) {
84  _type = DT_DIR;
85  } else {
86  _type = DT_REG;
87  }
88  }
89 
90  size_t FATFile::size() const
91  {
92  return _reader.size(*this);
93  }
94 
95  time_t FATFile::lastaccess() const
96  {
97  return _reader.lastaccess(*this);
98  }
99 
100  time_t FATFile::lastmodify() const
101  {
102  return lastaccess();
103  }
104 
105  time_t FATFile::laststatchange() const
106  {
107  return lastaccess();
108  }
109 
111  {
112  return _reader;
113  }
114 }
bool isDirectory(const FATFile &file) const
FATFile(const FatImageReader &reader)
Definition: FATFile.cpp:32
virtual void update()
Definition: FATFile.cpp:81
virtual time_t lastaccess() const
Definition: FATFile.cpp:95
void list(filelist &files) const
virtual size_t size() const
Definition: FATFile.cpp:90
virtual ~FATFile()
Definition: FATFile.cpp:43
int getFiles(std::list< FATFile > &files) const
Definition: FATFile.cpp:47
time_t lastaccess(const FATFile &file) const
virtual time_t laststatchange() const
Definition: FATFile.cpp:105
FATFile getParent() const
Definition: FATFile.cpp:70
virtual time_t lastmodify() const
Definition: FATFile.cpp:100
FATFile get(const std::string &filename) const
Definition: FATFile.cpp:64
virtual int remove(bool recursive)
Definition: FATFile.cpp:58
virtual bool exists() const
Definition: FATFile.cpp:76
bool exists(const FATFile &file) const
size_t size(const FATFile &file) const
const FatImageReader & getReader() const
Definition: FATFile.cpp:110