File: CacheDir.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (71 lines) | stat: -rw-r--r-- 2,701 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef _CACHE_DIR_H
#define _CACHE_DIR_H

#include <string>

/**
 * Utility class, which helps in tagging a directory as beeing cache only,
 * by saving a certain, well defiend file in this dir.
 * This tag can be used when creating backups for example,
 * where the software creating backups could automatically exclude dirs
 * tagged with this method.
 * The file used as a tag:
 * name:    "CACHEDIR.TAG"
 * content: "Signature: 8a477f597d28d172789f06886806bc55"
 *
 * This is following a convention described here:
 * http://www.brynosaurus.com/cachedir/
 * and defined here:
 * http://www.brynosaurus.com/cachedir/spec.html
 */
class CacheDir {
private:
	// we do not want instances of this class
	CacheDir() {};

public:
	static const std::string tagFile_name;
	static const std::string tagFile_content;
	static const size_t      tagFile_content_size;
	static const std::string defaultAdditionalText;

	/**
	 * Checks if a dir is marked as beeing a cache dir.
	 * @return true if the dir exists and is tagged as cache dir, false otherwise
	 */
	static bool IsCacheDir(const std::string& dir);

	/**
	 * Sets or unsets a dir as cache dir.
	 * This removes or creates the tag file.
	 * @param dir directory to be used as cache
	 * @param wantedCacheState if true, writes a CACHEDIR.TAG
	 * @param additionalText only used if (wantedCacheState == true), is appended in the cache tag file
	 * @param forceRewrite if set to true, the tag file will be rewritten even if a valid one already exists (default: false)
	 * @return true if the dir tag file was successfully removed, created or already existed, false otherwise
	 */
	static bool SetCacheDir(const std::string& dir, bool wantedCacheState,
	                        const std::string& additionalText = CacheDir::defaultAdditionalText,
	                        bool forceRewrite = false);

private:
	/**
	 * Checks if the specified files content starts with the first content_size
	 * chars of content.
	 * @param filePath the file whichs content to compare to
	 * @param content the chars to compare to
	 * @param content_size how many chars to compare
	 * @return true if the this is a cache tag file, false otherwise
	 */
	static bool FileContentStartsWith(const std::string& filePath, const std::string& content, size_t content_size);
	/**
	 * Writes the cache tag file content to filePath.
	 * @return true if all content was successfully written, false otherwise
	 */
	static bool WriteCacheTagFile(const std::string& filePath, const std::string& additionalText);
	static std::string GetCacheTagFilePath(const std::string& dir);
};

#endif // _CACHE_DIR_H