bes  Updated for version 3.20.6
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 
44 using std::endl;
45 using std::ostream;
46 using std::string;
47 
54 BESFileContainer::BESFileContainer(const string &sym_name, const string &real_name, const string &type) :
55  BESContainer(sym_name, real_name, type), _cached(false), _target("")
56 {
57  string::size_type dotdot = real_name.find("..");
58  if (dotdot != string::npos) {
59  string s = (string) "'../' not allowed in container real name " + real_name;
60  throw BESForbiddenError(s, __FILE__, __LINE__);
61  }
62 }
63 
68 BESFileContainer::BESFileContainer(const BESFileContainer &copy_from) :
69  BESContainer(copy_from), _cached(copy_from._cached), _target(copy_from._target)
70 {}
71 
72 void BESFileContainer::_duplicate(BESContainer &copy_to)
73 {
74  BESContainer::_duplicate(copy_to);
75 }
76 
83 {
84  BESContainer *container = new BESFileContainer;
85  BESContainer::_duplicate(*container);
86  return container;
87 }
88 
95 {
96  BESDEBUG("cache2", "Entering " << __PRETTY_FUNCTION__ <<", real_name: " << get_real_name() << endl);
97 
98  // Get a pointer to the singleton cache instance for this process.
100 
101  // If the file is in the cache, this is nearly a no-op; if the file is compressed,
102  // uncompress it, add it to the class and return the name of the file in the cache.
103  // In both of those cases, the file is cached, so we need to record that so that
104  // the release() method will remove the lock on the cached file. If the file is not
105  // a compressed file, the 'uncompress' function returns false and the contents of
106  // the value-result parameter '_target' is undefined.
107  _cached = BESUncompressManager3::TheManager()->uncompress(get_real_name(), _target, cache);
108  if (_cached) {
109  BESDEBUG("cache2", "Cached as: " << _target << endl);
110  return _target;
111  }
112  else {
113  BESDEBUG("cache2", "Not cached" << endl);
114  return get_real_name();
115  }
116 }
117 
127 {
128  BESDEBUG("cache2", "Entering " << __PRETTY_FUNCTION__ <<", _cached: " << _cached << ", _target: " << _target << endl);
129  if (_cached)
131 
132  return true;
133 }
134 
142 void BESFileContainer::dump(ostream &strm) const
143 {
144  strm << BESIndent::LMarg << "BESFileContainer::dump - (" << (void *) this << ")" << endl;
145  BESIndent::Indent();
146  BESContainer::dump(strm);
147  BESIndent::UnIndent();
148 }
149 
BESUncompressCache
Definition: BESUncompressCache.h:28
BESFileContainer
Holds real data, container type and constraint for symbolic name read from persistence.
Definition: BESFileContainer.h:56
BESUncompressCache::get_instance
static BESUncompressCache * get_instance()
Definition: BESUncompressCache.cc:203
BESFileContainer::ptr_duplicate
virtual BESContainer * ptr_duplicate()
duplicate this instances of BESFileContainer
Definition: BESFileContainer.cc:82
BESUncompressManager3::uncompress
virtual bool uncompress(const std::string &src, std::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:135
BESFileLockingCache::unlock_and_close
virtual void unlock_and_close(const std::string &target)
Definition: BESFileLockingCache.cc:713
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:65
BESFileContainer::dump
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
Definition: BESFileContainer.cc:142
BESContainer::get_real_name
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
Definition: BESContainer.h:180
BESFileContainer::release
virtual bool release()
release the file
Definition: BESFileContainer.cc:126
BESFileContainer::access
virtual std::string access()
returns the name of a file to access for this container, uncompressing if necessary.
Definition: BESFileContainer.cc:94
BESContainer::_duplicate
void _duplicate(BESContainer &copy_to)
duplicate this instance into the passed container
Definition: BESContainer.cc:54
BESContainer::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESContainer.cc:73