2 * Copyright 2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Oliver Tappe <zooey@hirschkaefer.de>
10 #include <package/ValidateChecksumJob.h>
14 #include <package/Context.h>
17 namespace BPackageKit
{
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
;
43 ValidateChecksumJob::Execute()
45 if (fExpectedChecksumAccessor
== NULL
|| fRealChecksumAccessor
== NULL
)
48 BString expectedChecksum
;
51 status_t result
= fExpectedChecksumAccessor
->GetChecksum(expectedChecksum
);
55 result
= fRealChecksumAccessor
->GetChecksum(realChecksum
);
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
);
74 ValidateChecksumJob::ChecksumsMatch() const
76 return fChecksumsMatch
;
80 } // namespace BPrivate
82 } // namespace BPackageKit