bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 "config.h"
34
35#include "BESFileContainer.h"
36#include "TheBESKeys.h"
37
38// New cache system
39#include "BESUncompressManager3.h"
40#include "BESUncompressCache.h"
41
42#include "BESForbiddenError.h"
43
44#include "BESDebug.h"
45
46using std::endl;
47using std::ostream;
48using std::string;
49
50#define MODULE "cache2"
51#define prolog std::string("BESFileContainer::").append(__func__).append("() - ")
52
53
54
55
62BESFileContainer::BESFileContainer(const string &sym_name, const string &real_name, const string &type) :
63 BESContainer(sym_name, real_name, type), _cached(false), _target("")
64{
65 string::size_type dotdot = real_name.find("..");
66 if (dotdot != string::npos) {
67 string s = prolog + "'../' not allowed in container real name " + real_name;
68 throw BESForbiddenError(s, __FILE__, __LINE__);
69 }
70}
71
76BESFileContainer::BESFileContainer(const BESFileContainer &copy_from) :
77 BESContainer(copy_from), _cached(copy_from._cached), _target(copy_from._target)
78{}
79
80void BESFileContainer::_duplicate(BESContainer &copy_to)
81{
83}
84
91{
92 BESContainer *container = new BESFileContainer;
93 BESContainer::_duplicate(*container);
94 return container;
95}
96
103{
104 BESDEBUG(MODULE, prolog << "BEGIN real_name: " << get_real_name() << endl);
105
106 // Get a pointer to the singleton cache instance for this process.
108
109 // If the file is in the cache, this is nearly a no-op; if the file is compressed,
110 // uncompress it, add it to the class and return the name of the file in the cache.
111 // In both of those cases, the file is cached, so we need to record that so that
112 // the release() method will remove the lock on the cached file. If the file is not
113 // a compressed file, the 'uncompress' function returns false and the contents of
114 // the value-result parameter '_target' is undefined.
115 _cached = BESUncompressManager3::TheManager()->uncompress(get_real_name(), _target, cache);
116 if (_cached) {
117 BESDEBUG(MODULE, prolog << "END Cached as: " << _target << endl);
118 return _target;
119 }
120 else {
121 BESDEBUG(MODULE, prolog << "END Not cached" << endl);
122 return get_real_name();
123 }
124}
125
135{
136 BESDEBUG(MODULE, prolog << "_cached: " << _cached << ", _target: " << _target << endl);
137 if (_cached)
139
140 return true;
141}
142
150void BESFileContainer::dump(ostream &strm) const
151{
152 strm << BESIndent::LMarg << prolog << "(" << (void *) this << ")" << endl;
153 BESIndent::Indent();
154 BESContainer::dump(strm);
155 BESIndent::UnIndent();
156}
157
A container is something that holds data. E.G., a netcdf file or a database entry.
void dump(std::ostream &strm) const override
dumps information about this object
void _duplicate(BESContainer &copy_to)
duplicate this instance into the passed container
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
virtual bool release()
release the file
virtual std::string access()
returns the name of a file to access for this container, uncompressing if necessary.
virtual BESContainer * ptr_duplicate()
duplicate this instances of BESFileContainer
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
virtual void unlock_and_close(const std::string &target)
error thrown if the BES is not allowed to access the resource requested
static BESUncompressCache * get_instance()