xref: /haiku/src/kits/package/TempfileManager.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright 2011, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Oliver Tappe <zooey@hirschkaefer.de>
7  */
8 
9 
10 #include <package/TempfileManager.h>
11 
12 
13 namespace BPackageKit {
14 
15 namespace BPrivate {
16 
17 
18 const BString TempfileManager::kDefaultName = "tmp-pkgkit-file-";
19 
20 
21 TempfileManager::TempfileManager()
22 	:
23 	fNextNumber(1)
24 {
25 }
26 
27 
28 TempfileManager::~TempfileManager()
29 {
30 	if (fBaseDirectory.InitCheck() != B_OK)
31 		return;
32 
33 	fBaseDirectory.Rewind();
34 	BEntry entry;
35 	while (fBaseDirectory.GetNextEntry(&entry) == B_OK)
36 		entry.Remove();
37 
38 	fBaseDirectory.GetEntry(&entry);
39 	entry.Remove();
40 }
41 
42 
43 void
44 TempfileManager::SetBaseDirectory(const BDirectory& baseDirectory)
45 {
46 	fBaseDirectory = baseDirectory;
47 }
48 
49 
50 BEntry
51 TempfileManager::Create(const BString& baseName)
52 {
53 	BString name = BString(baseName) << atomic_add(&fNextNumber, 1);
54 
55 	return BEntry(&fBaseDirectory, name.String());
56 }
57 
58 
59 }	// namespace BPrivate
60 
61 }	// namespace BPackageKit
62