~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/utils/unittest/googletest/include/gtest/internal/gtest-filepath.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2008, Google Inc.
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are
 
6
// met:
 
7
//
 
8
//     * Redistributions of source code must retain the above copyright
 
9
// notice, this list of conditions and the following disclaimer.
 
10
//     * Redistributions in binary form must reproduce the above
 
11
// copyright notice, this list of conditions and the following disclaimer
 
12
// in the documentation and/or other materials provided with the
 
13
// distribution.
 
14
//     * Neither the name of Google Inc. nor the names of its
 
15
// contributors may be used to endorse or promote products derived from
 
16
// this software without specific prior written permission.
 
17
//
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
//
 
30
// Author: keith.ray@gmail.com (Keith Ray)
 
31
//
 
32
// Google Test filepath utilities
 
33
//
 
34
// This header file declares classes and functions used internally by
 
35
// Google Test.  They are subject to change without notice.
 
36
//
 
37
// This file is #included in testing/base/internal/gtest-internal.h
 
38
// Do not include this header file separately!
 
39
 
 
40
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
 
41
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
 
42
 
 
43
#include <gtest/internal/gtest-string.h>
 
44
 
 
45
namespace testing {
 
46
namespace internal {
 
47
 
 
48
// FilePath - a class for file and directory pathname manipulation which
 
49
// handles platform-specific conventions (like the pathname separator).
 
50
// Used for helper functions for naming files in a directory for xml output.
 
51
// Except for Set methods, all methods are const or static, which provides an
 
52
// "immutable value object" -- useful for peace of mind.
 
53
// A FilePath with a value ending in a path separator ("like/this/") represents
 
54
// a directory, otherwise it is assumed to represent a file. In either case,
 
55
// it may or may not represent an actual file or directory in the file system.
 
56
// Names are NOT checked for syntax correctness -- no checking for illegal
 
57
// characters, malformed paths, etc.
 
58
 
 
59
class FilePath {
 
60
 public:
 
61
  FilePath() : pathname_("") { }
 
62
  FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
 
63
 
 
64
  explicit FilePath(const char* pathname) : pathname_(pathname) {
 
65
    Normalize();
 
66
  }
 
67
 
 
68
  explicit FilePath(const String& pathname) : pathname_(pathname) {
 
69
    Normalize();
 
70
  }
 
71
 
 
72
  FilePath& operator=(const FilePath& rhs) {
 
73
    Set(rhs);
 
74
    return *this;
 
75
  }
 
76
 
 
77
  void Set(const FilePath& rhs) {
 
78
    pathname_ = rhs.pathname_;
 
79
  }
 
80
 
 
81
  String ToString() const { return pathname_; }
 
82
  const char* c_str() const { return pathname_.c_str(); }
 
83
 
 
84
  // Returns the current working directory, or "" if unsuccessful.
 
85
  static FilePath GetCurrentDir();
 
86
 
 
87
  // Given directory = "dir", base_name = "test", number = 0,
 
88
  // extension = "xml", returns "dir/test.xml". If number is greater
 
89
  // than zero (e.g., 12), returns "dir/test_12.xml".
 
90
  // On Windows platform, uses \ as the separator rather than /.
 
91
  static FilePath MakeFileName(const FilePath& directory,
 
92
                               const FilePath& base_name,
 
93
                               int number,
 
94
                               const char* extension);
 
95
 
 
96
  // Returns a pathname for a file that does not currently exist. The pathname
 
97
  // will be directory/base_name.extension or
 
98
  // directory/base_name_<number>.extension if directory/base_name.extension
 
99
  // already exists. The number will be incremented until a pathname is found
 
100
  // that does not already exist.
 
101
  // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
 
102
  // There could be a race condition if two or more processes are calling this
 
103
  // function at the same time -- they could both pick the same filename.
 
104
  static FilePath GenerateUniqueFileName(const FilePath& directory,
 
105
                                         const FilePath& base_name,
 
106
                                         const char* extension);
 
107
 
 
108
  // Returns true iff the path is NULL or "".
 
109
  bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; }
 
110
 
 
111
  // If input name has a trailing separator character, removes it and returns
 
112
  // the name, otherwise return the name string unmodified.
 
113
  // On Windows platform, uses \ as the separator, other platforms use /.
 
114
  FilePath RemoveTrailingPathSeparator() const;
 
115
 
 
116
  // Returns a copy of the FilePath with the directory part removed.
 
117
  // Example: FilePath("path/to/file").RemoveDirectoryName() returns
 
118
  // FilePath("file"). If there is no directory part ("just_a_file"), it returns
 
119
  // the FilePath unmodified. If there is no file part ("just_a_dir/") it
 
120
  // returns an empty FilePath ("").
 
121
  // On Windows platform, '\' is the path separator, otherwise it is '/'.
 
122
  FilePath RemoveDirectoryName() const;
 
123
 
 
124
  // RemoveFileName returns the directory path with the filename removed.
 
125
  // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
 
126
  // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
 
127
  // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
 
128
  // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
 
129
  // On Windows platform, '\' is the path separator, otherwise it is '/'.
 
130
  FilePath RemoveFileName() const;
 
131
 
 
132
  // Returns a copy of the FilePath with the case-insensitive extension removed.
 
133
  // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
 
134
  // FilePath("dir/file"). If a case-insensitive extension is not
 
135
  // found, returns a copy of the original FilePath.
 
136
  FilePath RemoveExtension(const char* extension) const;
 
137
 
 
138
  // Creates directories so that path exists. Returns true if successful or if
 
139
  // the directories already exist; returns false if unable to create
 
140
  // directories for any reason. Will also return false if the FilePath does
 
141
  // not represent a directory (that is, it doesn't end with a path separator).
 
142
  bool CreateDirectoriesRecursively() const;
 
143
 
 
144
  // Create the directory so that path exists. Returns true if successful or
 
145
  // if the directory already exists; returns false if unable to create the
 
146
  // directory for any reason, including if the parent directory does not
 
147
  // exist. Not named "CreateDirectory" because that's a macro on Windows.
 
148
  bool CreateFolder() const;
 
149
 
 
150
  // Returns true if FilePath describes something in the file-system,
 
151
  // either a file, directory, or whatever, and that something exists.
 
152
  bool FileOrDirectoryExists() const;
 
153
 
 
154
  // Returns true if pathname describes a directory in the file-system
 
155
  // that exists.
 
156
  bool DirectoryExists() const;
 
157
 
 
158
  // Returns true if FilePath ends with a path separator, which indicates that
 
159
  // it is intended to represent a directory. Returns false otherwise.
 
160
  // This does NOT check that a directory (or file) actually exists.
 
161
  bool IsDirectory() const;
 
162
 
 
163
  // Returns true if pathname describes a root directory. (Windows has one
 
164
  // root directory per disk drive.)
 
165
  bool IsRootDirectory() const;
 
166
 
 
167
 private:
 
168
  // Replaces multiple consecutive separators with a single separator.
 
169
  // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
 
170
  // redundancies that might be in a pathname involving "." or "..".
 
171
  //
 
172
  // A pathname with multiple consecutive separators may occur either through
 
173
  // user error or as a result of some scripts or APIs that generate a pathname
 
174
  // with a trailing separator. On other platforms the same API or script
 
175
  // may NOT generate a pathname with a trailing "/". Then elsewhere that
 
176
  // pathname may have another "/" and pathname components added to it,
 
177
  // without checking for the separator already being there.
 
178
  // The script language and operating system may allow paths like "foo//bar"
 
179
  // but some of the functions in FilePath will not handle that correctly. In
 
180
  // particular, RemoveTrailingPathSeparator() only removes one separator, and
 
181
  // it is called in CreateDirectoriesRecursively() assuming that it will change
 
182
  // a pathname from directory syntax (trailing separator) to filename syntax.
 
183
 
 
184
  void Normalize();
 
185
 
 
186
  String pathname_;
 
187
};  // class FilePath
 
188
 
 
189
}  // namespace internal
 
190
}  // namespace testing
 
191
 
 
192
#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_