bes  Updated for version 3.20.5
BESFileContainer.cc
1 // BESFileContainer.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "BESFileContainer.h"
34 #include "TheBESKeys.h"
35 
36 // New cache system
37 #include "BESUncompressManager3.h"
38 #include "BESUncompressCache.h"
39 
40 #include "BESForbiddenError.h"
41 
42 #include "BESDebug.h"
43 
50 BESFileContainer::BESFileContainer(const string &sym_name, const string &real_name, const string &type) :
51  BESContainer(sym_name, real_name, type), _cached(false), _target("")
52 {
53  string::size_type dotdot = real_name.find("..");
54  if (dotdot != string::npos) {
55  string s = (string) "'../' not allowed in container real name " + real_name;
56  throw BESForbiddenError(s, __FILE__, __LINE__);
57  }
58 }
59 
64 BESFileContainer::BESFileContainer(const BESFileContainer &copy_from) :
65  BESContainer(copy_from), _cached(copy_from._cached), _target(copy_from._target)
66 {}
67 
68 void BESFileContainer::_duplicate(BESContainer &copy_to)
69 {
70  BESContainer::_duplicate(copy_to);
71 }
72 
79 {
80  BESContainer *container = new BESFileContainer;
81  BESContainer::_duplicate(*container);
82  return container;
83 }
84 
91 {
92  BESDEBUG("cache2", "Entering " << __PRETTY_FUNCTION__ <<", real_name: " << get_real_name() << endl);
93 
94  // Get a pointer to the singleton cache instance for this process.
96 
97  // If the file is in the cache, this is nearly a no-op; if the file is compressed,
98  // uncompress it, add it to the class and return the name of the file in the cache.
99  // In both of those cases, the file is cached, so we need to record that so that
100  // the release() method will remove the lock on the cached file. If the file is not
101  // a compressed file, the 'uncompress' function returns false and the contents of
102  // the value-result parameter '_target' is undefined.
103  _cached = BESUncompressManager3::TheManager()->uncompress(get_real_name(), _target, cache);
104  if (_cached) {
105  BESDEBUG("cache2", "Cached as: " << _target << endl);
106  return _target;
107  }
108  else {
109  BESDEBUG("cache2", "Not cached" << endl);
110  return get_real_name();
111  }
112 }
113 
123 {
124  BESDEBUG("cache2", "Entering " << __PRETTY_FUNCTION__ <<", _cached: " << _cached << ", _target: " << _target << endl);
125  if (_cached)
127 
128  return true;
129 }
130 
138 void BESFileContainer::dump(ostream &strm) const
139 {
140  strm << BESIndent::LMarg << "BESFileContainer::dump - (" << (void *) this << ")" << endl;
141  BESIndent::Indent();
142  BESContainer::dump(strm);
143  BESIndent::UnIndent();
144 }
145 
BESUncompressCache
Definition: BESUncompressCache.h:28
BESFileContainer
Holds real data, container type and constraint for symbolic name read from persistence.
Definition: BESFileContainer.h:59
BESUncompressManager3::uncompress
virtual bool uncompress(const string &src, string &target, BESFileLockingCache *cache)
If the file 'src' should be uncompressed, do so and return a new file name on the value-result param ...
Definition: BESUncompressManager3.cc:132
BESUncompressCache::get_instance
static BESUncompressCache * get_instance()
Definition: BESUncompressCache.cc:200
BESFileContainer::ptr_duplicate
virtual BESContainer * ptr_duplicate()
duplicate this instances of BESFileContainer
Definition: BESFileContainer.cc:78
BESContainer::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESContainer.cc:70
BESFileLockingCache::unlock_and_close
virtual void unlock_and_close(const std::string &target)
Definition: BESFileLockingCache.cc:711
BESFileContainer::dump
virtual void dump(ostream &strm) const
Displays debug information about this object.
Definition: BESFileContainer.cc:138
BESForbiddenError
error thrown if the BES is not allowed to access the resource requested
Definition: BESForbiddenError.h:40
BESContainer
A container is something that holds data. E.G., a netcdf file or a database entry.
Definition: BESContainer.h:68
BESFileContainer::release
virtual bool release()
release the file
Definition: BESFileContainer.cc:122
BESFileContainer::access
virtual string access()
returns the name of a file to access for this container, uncompressing if necessary.
Definition: BESFileContainer.cc:90
BESContainer::_duplicate
void _duplicate(BESContainer &copy_to)
duplicate this instance into the passed container
Definition: BESContainer.cc:51
BESContainer::get_real_name
string get_real_name() const
retrieve the real name for this container, such as a file name.
Definition: BESContainer.h:183