BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / ValidateChecksumJob.cpp
blob9896bfb748255663529220ecb0a44a15201ef93d
1 /*
2 * Copyright 2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Oliver Tappe <zooey@hirschkaefer.de>
7 */
10 #include <package/ValidateChecksumJob.h>
12 #include <File.h>
14 #include <package/Context.h>
17 namespace BPackageKit {
19 namespace BPrivate {
22 ValidateChecksumJob::ValidateChecksumJob(const BContext& context,
23 const BString& title, ChecksumAccessor* expectedChecksumAccessor,
24 ChecksumAccessor* realChecksumAccessor, bool failIfChecksumsDontMatch)
26 inherited(context, title),
27 fExpectedChecksumAccessor(expectedChecksumAccessor),
28 fRealChecksumAccessor(realChecksumAccessor),
29 fFailIfChecksumsDontMatch(failIfChecksumsDontMatch),
30 fChecksumsMatch(false)
35 ValidateChecksumJob::~ValidateChecksumJob()
37 delete fRealChecksumAccessor;
38 delete fExpectedChecksumAccessor;
42 status_t
43 ValidateChecksumJob::Execute()
45 if (fExpectedChecksumAccessor == NULL || fRealChecksumAccessor == NULL)
46 return B_BAD_VALUE;
48 BString expectedChecksum;
49 BString realChecksum;
51 status_t result = fExpectedChecksumAccessor->GetChecksum(expectedChecksum);
52 if (result != B_OK)
53 return result;
55 result = fRealChecksumAccessor->GetChecksum(realChecksum);
56 if (result != B_OK)
57 return result;
59 fChecksumsMatch = expectedChecksum.ICompare(realChecksum) == 0;
61 if (fFailIfChecksumsDontMatch && !fChecksumsMatch) {
62 BString error = BString("Checksum error:\n")
63 << "expected '" << expectedChecksum << "'\n"
64 << "got '" << realChecksum << "'";
65 SetErrorString(error);
66 return B_BAD_DATA;
69 return B_OK;
73 bool
74 ValidateChecksumJob::ChecksumsMatch() const
76 return fChecksumsMatch;
80 } // namespace BPrivate
82 } // namespace BPackageKit