HaikuDepot: Better Logging

Changes the logging in HD to use a macro for the
various log levels to declutter the code and to
make it easier to more systematically log.

Change-Id: I025970707a0a11e7e3aaa4b52fc91288af0183f5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3018
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Andrew Lindesay 2020-07-11 15:23:49 +12:00
parent 2ad7efd4b5
commit f96d1f4d92
40 changed files with 515 additions and 610 deletions

View File

@ -1,14 +1,14 @@
/*
* Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "Captcha.h"
#include <stdio.h>
#include <DataIO.h>
#include "Logger.h"
// These are keys that are used to store this object's data into a BMessage
// instance.
@ -22,15 +22,15 @@ Captcha::Captcha(BMessage* from)
fPngImageData(NULL)
{
if (from->FindString(KEY_TOKEN, &fToken) != B_OK) {
printf("expected key [%s] in the message data when creating a "
"Captcha\n", KEY_TOKEN);
HDERROR("expected key [%s] in the message data when creating a "
"captcha", KEY_TOKEN)
}
const void* data;
ssize_t len;
if (from->FindData(KEY_PNG_IMAGE_DATA, B_ANY_TYPE, &data, &len) != B_OK)
printf("expected key [%s] in the message data\n", KEY_PNG_IMAGE_DATA);
HDERROR("expected key [%s] in the message data", KEY_PNG_IMAGE_DATA)
else
SetPngImageData(data, len);
}

View File

@ -70,8 +70,7 @@ void
LanguageModel::_SetPreferredLanguage(const Language& language)
{
fPreferredLanguage = LanguageRef(new Language(language));
if(Logger::IsDebugEnabled())
printf("set preferred language [%s]\n", language.Code());
HDDEBUG("set preferred language [%s]", language.Code())
}
@ -98,11 +97,7 @@ Language
LanguageModel::_DeriveDefaultLanguage() const
{
Language defaultLanguage = _DeriveSystemDefaultLanguage();
if(Logger::IsDebugEnabled()) {
printf("derived system default language [%s]\n",
defaultLanguage.Code());
}
HDDEBUG("derived system default language [%s]", defaultLanguage.Code())
// if there are no supported languages; as is the case to start with as the
// application starts, the default language from the system is used anyway.
@ -119,15 +114,15 @@ LanguageModel::_DeriveDefaultLanguage() const
defaultLanguage.Code());
if (foundSupportedLanguage == NULL) {
printf("unable to find the language [%s] - looking for app default",
defaultLanguage.Code());
HDERROR("unable to find the language [%s] - looking for app default",
defaultLanguage.Code())
foundSupportedLanguage = _FindSupportedLanguage(
LANGUAGE_DEFAULT.Code());
}
if (foundSupportedLanguage == NULL) {
printf("unable to find the app default language - using the first "
"supported language");
HDERROR("unable to find the app default language - using the first "
"supported language")
foundSupportedLanguage = fSupportedLanguages.ItemAt(0);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "Logger.h"
@ -22,7 +22,28 @@ Logger::SetLevel(log_level value)
}
bool
/*static*/
const char*
Logger::NameForLevel(log_level value)
{
switch (value) {
case LOG_LEVEL_OFF:
return "off";
case LOG_LEVEL_INFO:
return "info";
case LOG_LEVEL_DEBUG:
return "debug";
case LOG_LEVEL_TRACE:
return "trace";
case LOG_LEVEL_ERROR:
return "error";
default:
return "?";
}
}
/*static*/ bool
Logger::SetLevelByName(const char *name)
{
if (strcmp(name, "off") == 0) {
@ -33,6 +54,8 @@ Logger::SetLevelByName(const char *name)
fLevel = LOG_LEVEL_DEBUG;
} else if (strcmp(name, "trace") == 0) {
fLevel = LOG_LEVEL_TRACE;
} else if (strcmp(name, "error") == 0) {
fLevel = LOG_LEVEL_ERROR;
} else {
return false;
}
@ -41,22 +64,30 @@ Logger::SetLevelByName(const char *name)
}
/*static*/
bool
Logger::IsLevelEnabled(log_level value)
{
return fLevel >= value;
}
bool
Logger::IsInfoEnabled()
{
return fLevel >= LOG_LEVEL_INFO;
return IsLevelEnabled(LOG_LEVEL_INFO);
}
bool
Logger::IsDebugEnabled()
{
return fLevel >= LOG_LEVEL_DEBUG;
return IsLevelEnabled(LOG_LEVEL_DEBUG);
}
bool
Logger::IsTraceEnabled()
{
return fLevel >= LOG_LEVEL_TRACE;
return IsLevelEnabled(LOG_LEVEL_TRACE);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef LOGGER_H
@ -9,14 +9,38 @@
#include <File.h>
#include <Path.h>
#include "PackageInfo.h"
#include <ctype.h>
#include <stdio.h>
// These macros allow for standardized logging to be output.
// The use of macros in this way means that the use of the log is concise where
// it is used and also because the macro unwraps to a block contained with a
// condition statement, if the log level is not sufficient to trigger the log
// line then there is no computational cost to running over the log space. This
// is because the arguments will not be evaluated. Avoiding all of the
// conditional clauses in the code to prevent this otherwise would be
// cumbersome.
#define HDLOGPREFIX(L) printf("{%c} ", toupper(Logger::NameForLevel(L)[0]));
#define HDLOG(L, M...) if (Logger::IsLevelEnabled(L)) { \
HDLOGPREFIX(L) \
printf(M); \
putchar('\n'); \
}
#define HDINFO(M...) HDLOG(LOG_LEVEL_INFO, M)
#define HDDEBUG(M...) HDLOG(LOG_LEVEL_DEBUG, M)
#define HDTRACE(M...) HDLOG(LOG_LEVEL_TRACE, M)
#define HDERROR(M...) HDLOG(LOG_LEVEL_ERROR, M)
typedef enum log_level {
LOG_LEVEL_OFF = 1,
LOG_LEVEL_INFO = 2,
LOG_LEVEL_DEBUG = 3,
LOG_LEVEL_TRACE = 4
LOG_LEVEL_ERROR = 2,
LOG_LEVEL_INFO = 3,
LOG_LEVEL_DEBUG = 4,
LOG_LEVEL_TRACE = 5
} log_level;
@ -26,6 +50,9 @@ public:
static void SetLevel(log_level value);
static bool SetLevelByName(const char *name);
static const char* NameForLevel(log_level value);
static bool IsLevelEnabled(log_level value);
static bool IsInfoEnabled();
static bool IsDebugEnabled();
static bool IsTraceEnabled();

View File

@ -9,7 +9,6 @@
#include <ctime>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <Autolock.h>
@ -187,13 +186,9 @@ public:
if (package.Get() == NULL)
return false;
printf("TEST %s\n", package->Name().String());
for (int32 i = 0; i < fPackageLists.CountItems(); i++) {
if (fPackageLists.ItemAtFast(i)->Contains(package)) {
printf(" contained in %" B_PRId32 "\n", i);
if (fPackageLists.ItemAtFast(i)->Contains(package))
return false;
}
}
return true;
}
@ -649,8 +644,8 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
BString code;
if (item.FindString("code", &code) != B_OK) {
printf("corrupt user rating at index %" B_PRIi32 "\n",
index);
HDERROR("corrupt user rating at index %" B_PRIi32,
index)
continue;
}
@ -658,8 +653,8 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
BMessage userInfo;
if (item.FindMessage("user", &userInfo) != B_OK
|| userInfo.FindString("nickname", &user) != B_OK) {
printf("ignored user rating [%s] without a user "
"nickname\n", code.String());
HDERROR("ignored user rating [%s] without a user "
"nickname", code.String())
continue;
}
@ -672,8 +667,8 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
if (item.FindDouble("rating", &rating) != B_OK)
rating = -1;
if (comment.Length() == 0 && rating == -1) {
printf("rating [%s] has no comment or rating so will be"
"ignored\n", code.String());
HDERROR("rating [%s] has no comment or rating so will"
" be ignored", code.String())
continue;
}
@ -717,22 +712,15 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
comment, languageCode, versionString,
(uint64) createTimestamp);
package->AddUserRating(userRating);
if (Logger::IsDebugEnabled()) {
printf("rating [%s] retrieved from server\n",
code.String());
}
}
if (Logger::IsDebugEnabled()) {
printf("did retrieve %" B_PRIi32 " user ratings for [%s]\n",
index - 1, packageName.String());
HDDEBUG("rating [%s] retrieved from server", code.String())
}
HDDEBUG("did retrieve %" B_PRIi32 " user ratings for [%s]",
index - 1, packageName.String())
} else {
_MaybeLogJsonRpcError(info, "retrieve user ratings");
}
} else {
printf("unable to retrieve user ratings\n");
HDERROR("unable to retrieve user ratings")
}
}
@ -773,22 +761,16 @@ Model::_PopulatePackageChangelog(const PackageInfoRef& package)
&& 0 != content.Length()) {
BAutolock locker(&fLock);
package->SetChangelog(content);
if (Logger::IsDebugEnabled()) {
fprintf(stdout, "changelog populated for [%s]\n",
packageName.String());
}
HDDEBUG("changelog populated for [%s]", packageName.String())
} else {
if (Logger::IsDebugEnabled()) {
fprintf(stdout, "no changelog present for [%s]\n",
packageName.String());
}
HDDEBUG("no changelog present for [%s]", packageName.String())
}
} else {
_MaybeLogJsonRpcError(info, "populate package changelog");
}
} else {
fprintf(stdout, "unable to obtain the changelog for the package"
" [%s]\n", packageName.String());
HDERROR("unable to obtain the changelog for the package [%s]",
packageName.String())
}
}
@ -809,15 +791,15 @@ model_remove_key_for_user(const BString& nickname)
case B_OK:
result = keyStore.RemoveKey(kHaikuDepotKeyring, key);
if (result != B_OK) {
printf("! error occurred when removing password for nickname "
"[%s] : %s\n", nickname.String(), strerror(result));
HDERROR("error occurred when removing password for nickname "
"[%s] : %s", nickname.String(), strerror(result))
}
break;
case B_ENTRY_NOT_FOUND:
return;
default:
printf("! error occurred when finding password for nickname "
"[%s] : %s\n", nickname.String(), strerror(result));
HDERROR("error occurred when finding password for nickname "
"[%s] : %s", nickname.String(), strerror(result))
break;
}
}
@ -956,7 +938,7 @@ Model::_PopulatePackageScreenshot(const PackageInfoRef& package,
"Screenshots", screenshotCachePath);
if (result != B_OK) {
printf("[!] unable to get the screenshot dir - unable to proceed");
HDERROR("unable to get the screenshot dir - unable to proceed")
return;
}
@ -1007,9 +989,9 @@ Model::_PopulatePackageScreenshot(const PackageInfoRef& package,
screenshotFile.Write(buffer.Buffer(), buffer.BufferLength());
}
} else {
fprintf(stderr, "Failed to retrieve screenshot for code '%s' "
"at %" B_PRIi32 "x%" B_PRIi32 ".\n", info.Code().String(),
scaledWidth, scaledHeight);
HDERROR("Failed to retrieve screenshot for code '%s' "
"at %" B_PRIi32 "x%" B_PRIi32 ".", info.Code().String(),
scaledWidth, scaledHeight)
}
}
@ -1070,13 +1052,15 @@ Model::LogDepotsWithNoWebAppRepositoryCode() const
const DepotInfo& depot = fDepots.ItemAt(i);
if (depot.WebAppRepositoryCode().Length() == 0) {
printf("depot [%s]", depot.Name().String());
if (depot.URL().Length() > 0)
printf(" (%s)", depot.URL().String());
printf(" correlates with no repository in the haiku"
"depot server system\n");
if (depot.URL().Length() > 0) {
HDINFO("depot [%s] (%s) correlates with no repository in the"
" the haiku depot server system", depot.Name().String(),
depot.URL().String())
}
else {
HDINFO("depot [%s] correlates with no repository in the"
" the haiku depot server system", depot.Name().String())
}
}
}
}
@ -1093,11 +1077,10 @@ Model::_MaybeLogJsonRpcError(const BMessage &responsePayload,
if (responsePayload.FindMessage("error", &error) == B_OK
&& error.FindString("message", &errorMessage) == B_OK
&& error.FindDouble("code", &errorCode) == B_OK) {
printf("[%s] --> error : [%s] (%f)\n", sourceDescription,
errorMessage.String(), errorCode);
HDERROR("[%s] --> error : [%s] (%f)", sourceDescription,
errorMessage.String(), errorCode)
} else {
printf("[%s] --> an undefined error has occurred\n", sourceDescription);
HDERROR("[%s] --> an undefined error has occurred", sourceDescription)
}
}

View File

@ -7,13 +7,12 @@
#include "PackageInfo.h"
#include <stdio.h>
#include <FindDirectory.h>
#include <package/PackageDefs.h>
#include <package/PackageFlags.h>
#include <Path.h>
#include "Logger.h"
// #pragma mark - Language
@ -1176,16 +1175,16 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
}
}
if (!found) {
printf("%s: new package: '%s'\n", fName.String(),
otherPackage->Name().String());
HDINFO("%s: new package: '%s'", fName.String(),
otherPackage->Name().String())
fPackages.Add(otherPackage);
}
}
for (int32 i = packages.CountItems() - 1; i >= 0; i--) {
const PackageInfoRef& package = packages.ItemAtFast(i);
printf("%s: removing package: '%s'\n", fName.String(),
package->Name().String());
HDINFO("%s: removing package: '%s'", fName.String(),
package->Name().String())
fPackages.Remove(package);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2017, Haiku, Inc. All Rights Reserved.
* Copyright 2013-2020, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -7,13 +7,12 @@
* Stephan Aßmus <superstippi@gmx.de>
* Rene Gollent <rene@gollent.com>
* Julian Harnath <julian.harnath@rwth-aachen.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/
#include "PackageManager.h"
#include <stdio.h>
#include <Alert.h>
#include <Catalog.h>
#include <Entry.h>
@ -36,6 +35,7 @@
#include "AutoDeleter.h"
#include "AutoLocker.h"
#include "Logger.h"
#include "Model.h"
#include "PackageInfo.h"
#include "ProblemWindow.h"
@ -163,19 +163,18 @@ public:
ref->SetState(state);
return ex.Error();
} catch (BAbortedByUserException& ex) {
fprintf(stderr, "Installation of package "
"%s aborted by user: %s\n", packageNameString,
ex.Message().String());
HDINFO("Installation of package %s is aborted by user: %s",
packageNameString, ex.Message().String())
_SetDownloadedPackagesState(NONE);
ref->SetState(state);
return B_OK;
} catch (BNothingToDoException& ex) {
fprintf(stderr, "Nothing to do while installing package "
"%s: %s\n", packageNameString, ex.Message().String());
HDINFO("Nothing to do while installing package %s: %s",
packageNameString, ex.Message().String())
return B_OK;
} catch (BException& ex) {
fprintf(stderr, "Exception occurred while installing package "
"%s: %s\n", packageNameString, ex.Message().String());
HDERROR("Exception occurred while installing package %s: %s",
packageNameString, ex.Message().String())
_SetDownloadedPackagesState(NONE);
ref->SetState(state);
return B_ERROR;
@ -291,8 +290,8 @@ public:
} catch (BNothingToDoException& ex) {
return B_OK;
} catch (BException& ex) {
fprintf(stderr, "Exception occurred while uninstalling package "
"%s: %s\n", packageName, ex.Message().String());
HDERROR("Exception occurred while uninstalling package %s: %s",
packageName, ex.Message().String())
ref->SetState(state);
return B_ERROR;
}
@ -390,9 +389,9 @@ public:
{
BString path = MakePath(entry);
if (path.FindFirst("data/deskbar/menu") == 0
&& entry->SymlinkPath() != NULL) {
printf("found deskbar entry: %s -> %s\n", path.String(),
entry->SymlinkPath());
&& entry->SymlinkPath() != NULL) {
HDINFO("found deskbar entry: %s -> %s",
path.String(), entry->SymlinkPath())
fDeskbarLinks.Add(DeskbarLink(path, entry->SymlinkPath()));
}
return B_OK;
@ -464,7 +463,7 @@ public:
BPath path;
if (fDeskbarLink.link.FindFirst('/') == 0) {
status = path.SetTo(fDeskbarLink.link);
printf("trying to launch (absolute link): %s\n", path.Path());
HDINFO("trying to launch (absolute link): %s", path.Path())
} else {
int32 location = InstallLocation();
if (location == B_PACKAGE_INSTALLATION_LOCATION_SYSTEM) {
@ -484,7 +483,7 @@ public:
status = path.GetParent(&path);
if (status == B_OK) {
status = path.Append(fDeskbarLink.link, true);
printf("trying to launch: %s\n", path.Path());
HDINFO("trying to launch: %s", path.Path())
}
}
@ -518,8 +517,8 @@ public:
return false;
}
} else {
printf("OpenPackageAction::FindAppToLaunch(): "
"unknown install location");
HDINFO("OpenPackageAction::FindAppToLaunch(): "
"unknown install location")
return false;
}
@ -530,9 +529,9 @@ public:
status_t status = reader.Init(packagePath.Path());
if (status != B_OK) {
printf("OpenPackageAction::FindAppToLaunch(): "
"failed to init BPackageReader(%s): %s\n",
packagePath.Path(), strerror(status));
HDINFO("OpenPackageAction::FindAppToLaunch(): "
"failed to init BPackageReader(%s): %s",
packagePath.Path(), strerror(status))
return false;
}
@ -540,9 +539,9 @@ public:
DeskbarLinkFinder contentHandler(foundLinks);
status = reader.ParseContent(&contentHandler);
if (status != B_OK) {
printf("OpenPackageAction::FindAppToLaunch(): "
"failed parse package contents (%s): %s\n",
packagePath.Path(), strerror(status));
HDINFO("OpenPackageAction::FindAppToLaunch(): "
"failed parse package contents (%s): %s",
packagePath.Path(), strerror(status))
return false;
}
@ -635,12 +634,12 @@ PackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
try {
result = BPackageManager::RefreshRepository(repoConfig);
} catch (BFatalErrorException& ex) {
fprintf(stderr, "Fatal error occurred while refreshing repository: "
"%s (%s)\n", ex.Message().String(), ex.Details().String());
HDERROR("Fatal error occurred while refreshing repository: "
"%s (%s)", ex.Message().String(), ex.Details().String())
result = ex.Error();
} catch (BException& ex) {
fprintf(stderr, "Exception occurred while refreshing "
"repository: %s\n", ex.Message().String());
HDERROR("Exception occurred while refreshing "
"repository: %s\n", ex.Message().String())
result = B_ERROR;
}
@ -657,13 +656,13 @@ PackageManager::DownloadPackage(const BString& fileURL,
result = BPackageManager::DownloadPackage(fileURL, targetEntry,
checksum);
} catch (BFatalErrorException& ex) {
fprintf(stderr, "Fatal error occurred while downloading package: "
"%s: %s (%s)\n", fileURL.String(), ex.Message().String(),
ex.Details().String());
HDERROR("Fatal error occurred while downloading package: "
"%s: %s (%s)", fileURL.String(), ex.Message().String(),
ex.Details().String())
result = ex.Error();
} catch (BException& ex) {
fprintf(stderr, "Exception occurred while downloading package "
"%s: %s\n", fileURL.String(), ex.Message().String());
HDERROR("Exception occurred while downloading package "
"%s: %s", fileURL.String(), ex.Message().String())
result = B_ERROR;
}

View File

@ -1,11 +1,11 @@
/*
* Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "UserUsageConditions.h"
#include <stdio.h>
#include "Logger.h"
// These are keys that are used to store this object's data into a BMessage
// instance.
@ -24,14 +24,14 @@ UserUsageConditions::UserUsageConditions(BMessage* from)
int16 minimumAge;
if (from->FindInt16(KEY_MINIMUM_AGE, &minimumAge) != B_OK)
printf("expected key [%s] in the message data\n", KEY_MINIMUM_AGE);
HDERROR("expected key [%s] in the message data", KEY_MINIMUM_AGE)
fMinimumAge = (uint8) minimumAge;
if (from->FindString(KEY_CODE, &fCode) != B_OK)
printf("expected key [%s] in the message data\n", KEY_CODE);
HDERROR("expected key [%s] in the message data", KEY_CODE)
if (from->FindString(KEY_COPY_MARKDOWN, &fCopyMarkdown) != B_OK)
printf("expected key [%s] in the message data\n", KEY_COPY_MARKDOWN);
HDERROR("expected key [%s] in the message data", KEY_COPY_MARKDOWN)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "AbstractProcess.h"
@ -47,12 +47,12 @@ AbstractProcess::Run()
AutoLocker<BLocker> locker(&fLock);
if (ProcessState() != PROCESS_INITIAL) {
printf("cannot start process as it is not idle");
HDINFO("cannot start process as it is not idle")
return B_NOT_ALLOWED;
}
if (fWasStopped) {
printf("cannot start process as it was stopped");
HDINFO("cannot start process as it was stopped")
return B_CANCELED;
}
@ -62,7 +62,7 @@ AbstractProcess::Run()
status_t runResult = RunInternal();
if (runResult != B_OK)
printf("[%s] an error has arisen; %s\n", Name(), strerror(runResult));
HDERROR("[%s] an error has arisen; %s", Name(), strerror(runResult))
BReference<AbstractProcessListener> listener;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -122,9 +122,9 @@ AbstractServerProcess::IfModifiedSinceHeaderValue(BString& headerValue,
headerValue.SetTo(modifiedHttpTime
.ToString(BPrivate::B_HTTP_TIME_FORMAT_COOKIE));
} else {
fprintf(stderr, "unable to parse the meta-data date and time from [%s]"
" - cannot set the 'If-Modified-Since' header\n",
metaDataPath.Path());
HDERROR("unable to parse the meta-data date and time from [%s]"
" - cannot set the 'If-Modified-Since' header",
metaDataPath.Path())
}
return result;
@ -148,8 +148,8 @@ AbstractServerProcess::PopulateMetaData(
return result;
if (!metaData.IsPopulated()) {
fprintf(stderr, "the meta data was read from [%s], but no values "
"were extracted\n", path.Path());
HDERROR("the meta data was read from [%s], but no values "
"were extracted", path.Path())
return B_BAD_DATA;
}
@ -179,8 +179,8 @@ AbstractServerProcess::ParseJsonFromFileWithListener(
FILE* file = fopen(pathStr, "rb");
if (file == NULL) {
printf("[%s] unable to find the meta data file at [%s]\n", Name(),
path.Path());
HDERROR("[%s] unable to find the meta data file at [%s]", Name(),
path.Path())
return B_FILE_NOT_FOUND;
}
@ -240,8 +240,8 @@ AbstractServerProcess::DownloadToLocalFileAtomically(
if (result == B_OK && hasFile && size > 0) {
if (rename(temporaryFilePath.Path(), targetFilePath.Path()) != 0) {
printf("[%s] did rename [%s] --> [%s]\n",
Name(), temporaryFilePath.Path(), targetFilePath.Path());
HDINFO("[%s] did rename [%s] --> [%s]",
Name(), temporaryFilePath.Path(), targetFilePath.Path())
result = B_IO_ERROR;
}
}
@ -259,18 +259,18 @@ AbstractServerProcess::DownloadToLocalFile(const BPath& targetFilePath,
return B_CANCELED;
if (redirects > MAX_REDIRECTS) {
printf("[%s] exceeded %d redirects --> failure\n", Name(),
MAX_REDIRECTS);
HDINFO("[%s] exceeded %d redirects --> failure", Name(),
MAX_REDIRECTS)
return B_IO_ERROR;
}
if (failures > MAX_FAILURES) {
printf("[%s] exceeded %d failures\n", Name(), MAX_FAILURES);
HDINFO("[%s] exceeded %d failures", Name(), MAX_FAILURES)
return B_IO_ERROR;
}
printf("[%s] will stream '%s' to [%s]\n", Name(), url.UrlString().String(),
targetFilePath.Path());
HDINFO("[%s] will stream '%s' to [%s]", Name(), url.UrlString().String(),
targetFilePath.Path())
ToFileUrlProtocolListener listener(targetFilePath, Name(),
Logger::IsTraceEnabled());
@ -314,12 +314,12 @@ AbstractServerProcess::DownloadToLocalFile(const BPath& targetFilePath,
fRequest = NULL;
if (BHttpRequest::IsSuccessStatusCode(statusCode)) {
fprintf(stdout, "[%s] did complete streaming data [%"
B_PRIdSSIZE " bytes]\n", Name(), listener.ContentLength());
HDINFO("[%s] did complete streaming data [%"
B_PRIdSSIZE " bytes]", Name(), listener.ContentLength())
return B_OK;
} else if (statusCode == B_HTTP_STATUS_NOT_MODIFIED) {
fprintf(stdout, "[%s] remote data has not changed since [%s]\n",
Name(), ifModifiedSinceHeader.String());
HDINFO("[%s] remote data has not changed since [%s]", Name(),
ifModifiedSinceHeader.String())
return HD_ERR_NOT_MODIFIED;
} else if (statusCode == B_HTTP_STATUS_PRECONDITION_FAILED) {
ServerHelper::NotifyClientTooOld(responseHeaders);
@ -327,25 +327,24 @@ AbstractServerProcess::DownloadToLocalFile(const BPath& targetFilePath,
} else if (BHttpRequest::IsRedirectionStatusCode(statusCode)) {
if (location.Length() != 0) {
BUrl redirectUrl(result.Url(), location);
fprintf(stdout, "[%s] will redirect to; %s\n",
Name(), redirectUrl.UrlString().String());
HDINFO("[%s] will redirect to; %s",
Name(), redirectUrl.UrlString().String())
return DownloadToLocalFile(targetFilePath, redirectUrl,
redirects + 1, 0);
}
fprintf(stdout, "[%s] unable to find 'Location' header for redirect\n",
Name());
HDERROR("[%s] unable to find 'Location' header for redirect", Name())
return B_IO_ERROR;
} else {
if (statusCode == 0 || (statusCode / 100) == 5) {
fprintf(stdout, "error response from server [%" B_PRId32 "] --> "
"retry...\n", statusCode);
HDERROR("error response from server [%" B_PRId32 "] --> retry...",
statusCode)
return DownloadToLocalFile(targetFilePath, url, redirects,
failures + 1);
}
fprintf(stdout, "[%s] unexpected response from server [%" B_PRId32 "]\n",
Name(), statusCode);
HDERROR("[%s] unexpected response from server [%" B_PRId32 "]",
Name(), statusCode)
return B_IO_ERROR;
}
}
@ -378,13 +377,13 @@ AbstractServerProcess::MoveDamagedFileAside(const BPath& currentFilePath)
damagedFilePath.Append(damagedLeaf.String());
if (0 != rename(currentFilePath.Path(), damagedFilePath.Path())) {
printf("[%s] unable to move damaged file [%s] aside to [%s]\n",
Name(), currentFilePath.Path(), damagedFilePath.Path());
HDERROR("[%s] unable to move damaged file [%s] aside to [%s]",
Name(), currentFilePath.Path(), damagedFilePath.Path())
return B_IO_ERROR;
}
printf("[%s] did move damaged file [%s] aside to [%s]\n",
Name(), currentFilePath.Path(), damagedFilePath.Path());
HDINFO("[%s] did move damaged file [%s] aside to [%s]",
Name(), currentFilePath.Path(), damagedFilePath.Path())
return B_OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -29,9 +29,7 @@ AbstractSingleFileServerProcess::~AbstractSingleFileServerProcess()
status_t
AbstractSingleFileServerProcess::RunInternal()
{
if (Logger::IsInfoEnabled())
printf("[%s] will fetch data\n", Name());
HDINFO("[%s] will fetch data", Name())
BPath localPath;
status_t result = GetLocalPath(localPath);
@ -58,15 +56,14 @@ AbstractSingleFileServerProcess::RunInternal()
if (!IsSuccess(result)) {
if (hasData) {
printf("[%s] failed to update data, but have old data "
"anyway so carry on with that\n", Name());
HDINFO("[%s] failed to update data, but have old data "
"anyway so carry on with that", Name())
result = B_OK;
} else {
printf("[%s] failed to obtain data\n", Name());
HDERROR("[%s] failed to obtain data", Name())
}
} else {
if (Logger::IsInfoEnabled())
printf("[%s] did fetch data\n", Name());
HDINFO("[%s] did fetch data", Name())
}
}
@ -81,12 +78,12 @@ AbstractSingleFileServerProcess::RunInternal()
}
if (IsSuccess(result)) {
printf("[%s] will process data\n", Name());
HDINFO("[%s] will process data", Name())
result = ProcessLocalData();
switch (result) {
case B_OK:
printf("[%s] did process data\n", Name());
HDINFO("[%s] did process data", Name())
break;
default:
MoveDamagedFileAside(localPath);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -89,9 +89,7 @@ LocalPkgDataLoadProcess::Description() const
status_t
LocalPkgDataLoadProcess::RunInternal()
{
if (Logger::IsDebugEnabled())
printf("[%s] will refresh the package list\n", Name());
HDDEBUG("[%s] will refresh the package list", Name())
BPackageRoster roster;
BStringList repositoryNames;
@ -111,16 +109,12 @@ LocalPkgDataLoadProcess::RunInternal()
if (getRepositoryConfigStatus == B_OK) {
depotInfo.SetURL(repoConfig.Identifier());
if (Logger::IsDebugEnabled()) {
printf("[%s] local repository [%s] info;\n"
" * url [%s]\n", Name(), repoName.String(),
repoConfig.Identifier().String());
}
HDDEBUG("[%s] local repository [%s] identifier; [%s]",
Name(), repoName.String(), repoConfig.Identifier().String())
} else {
printf("[%s] unable to obtain the repository config for local "
"repository '%s'; %s\n", Name(),
repoName.String(), strerror(getRepositoryConfigStatus));
HDINFO("[%s] unable to obtain the repository config for local "
"repository '%s'; %s", Name(),
repoName.String(), strerror(getRepositoryConfigStatus))
}
depots[i] = depotInfo;
@ -226,18 +220,12 @@ LocalPkgDataLoadProcess::RunInternal()
}
if (it == depots.end()) {
if (Logger::IsDebugEnabled()) {
printf("pkg [%s] repository [%s] not recognized"
" --> ignored\n",
modelInfo->Name().String(), repositoryName.String());
}
HDDEBUG("pkg [%s] repository [%s] not recognized --> ignored",
modelInfo->Name().String(), repositoryName.String())
} else {
it->AddPackage(modelInfo);
if (Logger::IsTraceEnabled()) {
printf("pkg [%s] assigned to [%s]\n",
modelInfo->Name().String(), repositoryName.String());
}
HDTRACE("pkg [%s] assigned to [%s]",
modelInfo->Name().String(), repositoryName.String());
}
remotePackages[modelInfo->Name()] = modelInfo;
@ -363,20 +351,19 @@ LocalPkgDataLoadProcess::RunInternal()
}
}
} catch (BFatalErrorException& ex) {
printf("Fatal exception occurred while resolving system dependencies: "
"%s, details: %s\n", strerror(ex.Error()), ex.Details().String());
HDERROR("Fatal exception occurred while resolving system dependencies: "
"%s, details: %s", strerror(ex.Error()), ex.Details().String())
} catch (BNothingToDoException&) {
// do nothing
} catch (BException& ex) {
printf("Exception occurred while resolving system dependencies: %s\n",
ex.Message().String());
HDERROR("Exception occurred while resolving system dependencies: %s",
ex.Message().String())
} catch (...) {
printf("Unknown exception occurred while resolving system "
"dependencies.\n");
HDERROR("Unknown exception occurred while resolving system "
"dependencies.")
}
if (Logger::IsDebugEnabled())
printf("did refresh the package list\n");
HDDEBUG("did refresh the package list")
return B_OK;
}
@ -385,8 +372,8 @@ LocalPkgDataLoadProcess::RunInternal()
void
LocalPkgDataLoadProcess::_NotifyError(const BString& messageText) const
{
printf("an error has arisen loading data of packages from local : %s\n",
messageText.String());
HDERROR("an error has arisen loading data of packages from local : %s",
messageText.String())
AppUtils::NotifySimpleError(
B_TRANSLATE("Local repository load error"),
messageText);

View File

@ -66,10 +66,7 @@ LocalRepositoryUpdateProcess::RunInternal()
{
BPackageRoster roster;
BStringList repoNames;
if (Logger::IsInfoEnabled()) {
printf("[%s] will update local repositories' caches\n", Name());
}
HDINFO("[%s] will update local repositories' caches", Name())
status_t result = roster.GetRepositoryNames(repoNames);
@ -91,9 +88,9 @@ LocalRepositoryUpdateProcess::RunInternal()
result = B_ERROR;
}
if (result == B_OK && Logger::IsInfoEnabled()) {
printf("[%s] did update %" B_PRIi32 " local repositories' caches\n",
Name(), repoNames.CountStrings());
if (result == B_OK) {
HDINFO("[%s] did update %" B_PRIi32 " local repositories' caches",
Name(), repoNames.CountStrings())
}
return result;
@ -106,34 +103,25 @@ LocalRepositoryUpdateProcess::_ShouldRunForRepositoryName(
BPackageKit::BRepositoryCache* cache)
{
if (fForce) {
if (Logger::IsInfoEnabled()) {
printf("[%s] am refreshing cache for repo [%s] as it was forced\n",
Name(), repoName.String());
}
HDINFO("[%s] am refreshing cache for repo [%s] as it was forced",
Name(), repoName.String())
return true;
}
if (roster.GetRepositoryCache(repoName, cache) != B_OK) {
if (Logger::IsInfoEnabled()) {
printf("[%s] am updating cache for repo [%s] as there was no"
" cache\n", Name(), repoName.String());
}
HDINFO("[%s] am updating cache for repo [%s] as there was no cache",
Name(), repoName.String())
return true;
}
if (static_cast<App*>(be_app)->IsFirstRun()) {
if (Logger::IsInfoEnabled()) {
printf("[%s] am updating cache for repo [%s] as this is the first"
" time that the application has run\n", Name(),
repoName.String());
}
HDINFO("[%s] am updating cache for repo [%s] as this is the first"
" time that the application has run", Name(), repoName.String())
return true;
}
if (Logger::IsDebugEnabled()) {
printf("[%s] skipped update local repo [%s] cache\n", Name(),
repoName.String());
}
HDDEBUG("[%s] skipped update local repo [%s] cache", Name(),
repoName.String())
return false;
}
@ -152,10 +140,8 @@ LocalRepositoryUpdateProcess::_RunForRepositoryName(const BString& repoName,
try {
BRefreshRepositoryRequest refreshRequest(context, repoConfig);
result = refreshRequest.Process();
if (Logger::IsInfoEnabled()) {
printf("[%s] did update local repo [%s] cache\n", Name(),
repoName.String());
}
HDINFO("[%s] did update local repo [%s] cache", Name(),
repoName.String());
result = B_OK;
} catch (BFatalErrorException& ex) {
_NotifyError(ex.Message(), ex.Details());
@ -182,8 +168,8 @@ void
LocalRepositoryUpdateProcess::_NotifyError(const BString& error,
const BString& details) const
{
printf("an error has arisen updating the local repositories : %s\n",
error.String());
HDINFO("an error has arisen updating the local repositories : %s",
error.String())
BString alertText(B_TRANSLATE("An error occurred while refreshing the "
"repository: %error%"));

View File

@ -142,13 +142,16 @@ ProcessCoordinator::Stop()
AutoLocker<BLocker> locker(&fLock);
if (!fWasStopped) {
fWasStopped = true;
printf("[Coordinator] will stop process coordinator\n");
HDINFO("[Coordinator] will stop process coordinator")
for (int32 i = 0; i < fNodes.CountItems(); i++) {
ProcessNode* node = fNodes.ItemAt(i);
printf("[%s] stopping process", node->Process()->Name());
if (node->Process()->ErrorStatus() != B_OK)
printf(" (error)\n");
printf("\n");
if (node->Process()->ErrorStatus() != B_OK) {
HDINFO("[Coordinator] stopping process [%s] (owing to error)",
node->Process()->Name());
} else {
HDINFO("[Coordinator] stopping process [%s]",
node->Process()->Name());
}
node->StopProcess();
}
}
@ -260,11 +263,8 @@ ProcessCoordinator::_CoordinateAndCallListener()
ProcessCoordinatorState
ProcessCoordinator::_Coordinate()
{
if (Logger::IsTraceEnabled())
printf("[Coordinator] will coordinate nodes\n");
HDTRACE("[Coordinator] will coordinate nodes")
AutoLocker<BLocker> locker(&fLock);
_StopSuccessorNodesToErroredOrStoppedNodes();
// go through the nodes and find those that are still to be run and
@ -276,16 +276,12 @@ ProcessCoordinator::_Coordinate()
if (node->AllPredecessorsComplete())
node->StartProcess();
else {
if (Logger::IsTraceEnabled()) {
printf("[Coordinator] all predecessors not complete -> "
"[%s] not started\n", node->Process()->Name());
}
HDTRACE("[Coordinator] all predecessors not complete -> "
"[%s] not started", node->Process()->Name());
}
} else {
if (Logger::IsTraceEnabled()) {
printf("[Coordinator] process [%s] running or complete\n",
node->Process()->Name());
}
HDTRACE("[Coordinator] process [%s] running or complete",
node->Process()->Name());
}
}
@ -318,10 +314,8 @@ ProcessCoordinator::_StopSuccessorNodes(ProcessNode* predecessorNode)
AbstractProcess* process = node->Process();
if (process->ProcessState() == PROCESS_INITIAL) {
if (Logger::IsDebugEnabled()) {
printf("[Coordinator] [%s] (failed) --> [%s] (stopping)\n",
predecessorNode->Process()->Name(), process->Name());
}
HDDEBUG("[Coordinator] [%s] (failed) --> [%s] (stopping)",
predecessorNode->Process()->Name(), process->Name())
node->StopProcess();
_StopSuccessorNodes(node);
}

View File

@ -16,6 +16,7 @@
#include "HaikuDepotConstants.h"
#include "LocalPkgDataLoadProcess.h"
#include "LocalRepositoryUpdateProcess.h"
#include "Logger.h"
#include "Model.h"
#include "PackageInfoListener.h"
#include "ProcessCoordinator.h"
@ -114,7 +115,7 @@ ProcessCoordinatorFactory::CreateBulkLoadCoordinator(
processCoordinator->AddNode(processNode);
}
} else {
printf("a problem has arisen getting the repository names.\n");
HDERROR("a problem has arisen getting the repository names.")
}
}
@ -128,8 +129,8 @@ ProcessCoordinatorFactory::_CalculateServerProcessOptions()
uint32 processOptions = 0;
if (ServerSettings::IsClientTooOld()) {
printf("bulk load proceeding without network communications "
"because the client is too old\n");
HDINFO("bulk load proceeding without network communications "
"because the client is too old")
processOptions |= SERVER_PROCESS_NO_NETWORKING;
}

View File

@ -58,8 +58,8 @@ ProcessNode::_SpinUntilProcessState(
usleep(SPIN_UNTIL_STARTED_DELAY_MI);
if (real_time_clock() - start > timeoutSeconds) {
printf("[Node<%s>] timeout waiting for process state\n",
Process()->Name());
HDERROR("[Node<%s>] timeout waiting for process state",
Process()->Name())
return B_ERROR;
}
}
@ -75,8 +75,7 @@ ProcessNode::StartProcess()
if (fWorker != B_BAD_THREAD_ID)
return B_BUSY;
if (Logger::IsInfoEnabled())
printf("[Node<%s>] initiating\n", Process()->Name());
HDINFO("[Node<%s>] initiating", Process()->Name())
fWorker = spawn_thread(&_StartProcess, Process()->Name(),
B_NORMAL_PRIORITY, Process());
@ -106,8 +105,8 @@ ProcessNode::StopProcess()
// down.
if (waitResult != B_OK) {
printf("[%s] process did not stop within timeout - will be stopped "
"uncleanly", Process()->Name());
HDINFO("[%s] process did not stop within timeout - will be stopped "
"uncleanly", Process()->Name())
kill_thread(fWorker);
}
@ -130,9 +129,7 @@ ProcessNode::_StartProcess(void* cookie)
{
AbstractProcess* process = static_cast<AbstractProcess*>(cookie);
if (Logger::IsInfoEnabled()) {
printf("[Node<%s>] starting process\n", process->Name());
}
HDINFO("[Node<%s>] starting process", process->Name())
process->Run();
return B_OK;

View File

@ -1,12 +1,11 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ServerIconExportUpdateProcess.h"
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
@ -40,7 +39,7 @@ ServerIconExportUpdateProcess::ServerIconExportUpdateProcess(
{
AutoLocker<BLocker> locker(fModel->Lock());
if (fModel->IconStoragePath(fLocalIconStoragePath) != B_OK) {
printf("[%s] unable to obtain the path for storing icons\n", Name());
HDINFO("[%s] unable to obtain the path for storing icons", Name())
fLocalIconStoragePath.Unset();
fLocalIconStore = NULL;
} else {
@ -116,10 +115,8 @@ ServerIconExportUpdateProcess::Populate()
depots = fModel->Depots();
}
if (Logger::IsDebugEnabled()) {
printf("[%s] will populate icons for %" B_PRId32 " depots\n", Name(),
depots.CountItems());
}
HDDEBUG("[%s] will populate icons for %" B_PRId32 " depots", Name(),
depots.CountItems())
for (int32 i = 0;
(i < depots.CountItems()) && !WasStopped() && (result == B_OK);
@ -131,8 +128,8 @@ ServerIconExportUpdateProcess::Populate()
if (Logger::IsInfoEnabled()) {
double secs = watch.ElapsedTime() / 1000000.0;
printf("[%s] did populate %" B_PRId32 " packages' icons (%6.3g secs)\n",
Name(), fCountIconsSet, secs);
HDINFO("[%s] did populate %" B_PRId32 " packages' icons (%6.3g secs)",
Name(), fCountIconsSet, secs)
}
return result;
@ -144,8 +141,8 @@ ServerIconExportUpdateProcess::Populate()
status_t
ServerIconExportUpdateProcess::PopulateForDepot(const DepotInfo& depot)
{
printf("[%s] will populate icons for depot [%s]\n",
Name(), depot.Name().String());
HDINFO("[%s] will populate icons for depot [%s]",
Name(), depot.Name().String())
status_t result = B_OK;
const PackageList& packages = depot.Packages();
for(int32 j = 0;
@ -176,20 +173,16 @@ ServerIconExportUpdateProcess::PopulateForPkg(const PackageInfoRef& package)
BitmapRef bitmapRef(new(std::nothrow)SharedBitmap(bestIconFile), true);
package->SetIcon(bitmapRef);
if (Logger::IsDebugEnabled()) {
printf("[%s] have set the package icon for [%s] from [%s]\n",
Name(), package->Name().String(), bestIconPath.Path());
}
HDDEBUG("[%s] have set the package icon for [%s] from [%s]",
Name(), package->Name().String(), bestIconPath.Path())
fCountIconsSet++;
return B_OK;
}
if (Logger::IsDebugEnabled()) {
printf("[%s] did not set the package icon for [%s]; no data\n",
Name(), package->Name().String());
}
HDDEBUG("[%s] did not set the package icon for [%s]; no data",
Name(), package->Name().String())
return B_FILE_NOT_FOUND;
}
@ -201,13 +194,13 @@ ServerIconExportUpdateProcess::_DownloadAndUnpack()
BPath tarGzFilePath(tmpnam(NULL));
status_t result = B_OK;
printf("[%s] will start fetching icons\n", Name());
HDINFO("[%s] will start fetching icons", Name())
result = _Download(tarGzFilePath);
switch (result) {
case HD_ERR_NOT_MODIFIED:
printf("[%s] icons not modified - will use existing\n", Name());
HDINFO("[%s] icons not modified - will use existing", Name())
return result;
break;
case B_OK:
@ -231,14 +224,14 @@ ServerIconExportUpdateProcess::_HandleDownloadFailure()
if (result == B_OK) {
if (hasData) {
printf("[%s] failed to update data, but have old data anyway "
"so will carry on with that\n", Name());
HDINFO("[%s] failed to update data, but have old data anyway "
"so will carry on with that", Name())
} else {
printf("[%s] failed to obtain data\n", Name());
HDINFO("[%s] failed to obtain data", Name())
result = HD_ERR_NO_DATA;
}
} else {
printf("[%s] unable to detect if there is local data\n", Name());
HDERROR("[%s] unable to detect if there is local data\n", Name())
}
return result;
@ -253,7 +246,7 @@ status_t
ServerIconExportUpdateProcess::_Unpack(BPath& tarGzFilePath)
{
status_t result;
printf("[%s] delete any existing stored data\n", Name());
HDINFO("[%s] delete any existing stored data", Name())
StorageUtils::RemoveDirectoryContents(fLocalIconStoragePath);
BFile *tarGzFile = new BFile(tarGzFilePath.Path(), O_RDONLY);
@ -276,18 +269,17 @@ ServerIconExportUpdateProcess::_Unpack(BPath& tarGzFilePath)
if (result == B_OK) {
double secs = watch.ElapsedTime() / 1000000.0;
printf("[%s] did unpack icon tgz in (%6.3g secs)\n", Name(),
secs);
HDINFO("[%s] did unpack icon tgz in (%6.3g secs)", Name(), secs)
if (0 != remove(tarGzFilePath.Path())) {
printf("unable to delete the temporary tgz path; %s\n",
tarGzFilePath.Path());
HDERROR("[%s] unable to delete the temporary tgz path; %s",
Name(), tarGzFilePath.Path())
}
}
}
delete tarGzFile;
printf("[%s] did complete unpacking icons\n", Name());
HDINFO("[%s] did complete unpacking icons", Name())
return result;
}

View File

@ -143,8 +143,8 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package,
int categoryIndex = IndexOfCategoryByCode(*(categoryCode));
if (categoryIndex == -1) {
printf("unable to find the category for [%s]\n",
categoryCode->String());
HDERROR("unable to find the category for [%s]",
categoryCode->String())
} else {
package->AddCategory(
fCategories.ItemAtFast(categoryIndex));
@ -176,10 +176,8 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package,
));
}
if (fDebugEnabled) {
printf("did populate data for [%s] (%s)\n", pkg->Name()->String(),
fDepotName.String());
}
HDDEBUG("did populate data for [%s] (%s)", pkg->Name()->String(),
fDepotName.String())
fCount++;
@ -213,12 +211,12 @@ PackageFillingPkgListener::Handle(DumpExportPkg* pkg)
AutoLocker<BLocker> locker(fModel->Lock());
ConsumePackage(packageInfoRef, pkg);
} else {
printf("[PackageFillingPkgListener] unable to find the pkg [%s]\n",
packageName.String());
HDINFO("[PackageFillingPkgListener] unable to find the pkg [%s]",
packageName.String())
}
} else {
printf("[PackageFillingPkgListener] unable to find the depot [%s]\n",
fDepotName.String());
HDINFO("[PackageFillingPkgListener] unable to find the depot [%s]",
fDepotName.String())
}
return !fStoppable->WasStopped();
@ -322,8 +320,8 @@ ServerPkgDataUpdateProcess::ProcessLocalData()
if (Logger::IsInfoEnabled()) {
double secs = watch.ElapsedTime() / 1000000.0;
printf("[%s] did process %" B_PRIi32 " packages' data "
"in (%6.3g secs)\n", Name(), itemListener->Count(), secs);
HDINFO("[%s] did process %" B_PRIi32 " packages' data "
"in (%6.3g secs)", Name(), itemListener->Count(), secs)
}
return listener->ErrorStatus();
@ -362,11 +360,9 @@ status_t
ServerPkgDataUpdateProcess::RunInternal()
{
if (_DeriveWebAppRepositorySourceCode().IsEmpty()) {
if (Logger::IsInfoEnabled()) {
printf("[%s] am not updating data for depot [%s] as there is no"
" web app repository source code available\n",
Name(), fDepotName.String());
}
HDINFO("[%s] am not updating data for depot [%s] as there is no"
" web app repository source code available",
Name(), fDepotName.String())
return B_OK;
}

View File

@ -121,8 +121,8 @@ status_t
ServerReferenceDataUpdateProcess::_ProcessNaturalLanguages(
DumpExportReference* data)
{
printf("[%s] will populate %" B_PRId32 " natural languages\n",
Name(), data->CountNaturalLanguages());
HDINFO("[%s] will populate %" B_PRId32 " natural languages",
Name(), data->CountNaturalLanguages())
LanguageList result;
@ -143,8 +143,8 @@ ServerReferenceDataUpdateProcess::_ProcessNaturalLanguages(
fModel->Language().AddSupportedLanguages(result);
}
printf("[%s] did add %" B_PRId32 " supported languages\n",
Name(), result.CountItems());
HDINFO("[%s] did add %" B_PRId32 " supported languages",
Name(), result.CountItems())
return B_OK;
}
@ -154,8 +154,8 @@ status_t
ServerReferenceDataUpdateProcess::_ProcessPkgCategories(
DumpExportReference* data)
{
printf("[%s] will populate %" B_PRId32 " pkg categories\n",
Name(), data->CountPkgCategories());
HDINFO("[%s] will populate %" B_PRId32 " pkg categories",
Name(), data->CountPkgCategories())
CategoryList result;

View File

@ -102,18 +102,18 @@ DepotMatchingRepositoryListener::MapDepot(const DepotInfo& depot, void *context)
BString(*repositorySourceCode));
if (Logger::IsDebugEnabled()) {
printf("[DepotMatchingRepositoryListener] associated depot [%s] (%s) "
"with server repository source [%s] (%s)\n",
HDDEBUG("[DepotMatchingRepositoryListener] associated depot [%s] (%s) "
"with server repository source [%s] (%s)",
modifiedDepotInfo.Name().String(),
modifiedDepotInfo.URL().String(),
repositorySourceCode->String(),
repositoryAndRepositorySource
->repositorySource->Identifier()->String());
->repositorySource->Identifier()->String())
} else {
printf("[DepotMatchingRepositoryListener] associated depot [%s] with "
"server repository source [%s]\n",
HDINFO("[DepotMatchingRepositoryListener] associated depot [%s] with "
"server repository source [%s]",
modifiedDepotInfo.Name().String(),
repositorySourceCode->String());
repositorySourceCode->String())
}
return modifiedDepotInfo;
@ -133,7 +133,8 @@ DepotMatchingRepositoryListener::Handle(const BString& identifier,
void
DepotMatchingRepositoryListener::Handle(repository_and_repository_source& pair)
{
Handle(*(pair.repositorySource->Identifier()), pair);
if (!pair.repositorySource->IdentifierIsNull())
Handle(*(pair.repositorySource->Identifier()), pair);
// there may be additional identifiers for the remote repository and
// these should also be taken into consideration.

View File

@ -1,11 +1,10 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ServerSettings.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@ -17,6 +16,8 @@
#include <Roster.h>
#include <Url.h>
#include "Logger.h"
#define BASEURL_DEFAULT "https://depot.haiku-os.org"
#define USERAGENT_FALLBACK_VERSION "0.0.0"
@ -36,12 +37,12 @@ status_t
ServerSettings::SetBaseUrl(const BUrl& value)
{
if (!value.IsValid()) {
fprintf(stderr, "the url is not valid\n");
HDERROR("the url is not valid")
return B_BAD_VALUE;
}
if (value.Protocol() != "http" && value.Protocol() != "https") {
fprintf(stderr, "the url protocol must be 'http' or 'https'\n");
HDERROR("the url protocol must be 'http' or 'https'")
return B_BAD_VALUE;
}
@ -82,7 +83,7 @@ ServerSettings::_GetUserAgentVersionString()
app_info info;
if (be_app->GetAppInfo(&info) != B_OK) {
fprintf(stderr, "Unable to get the application info\n");
HDERROR("Unable to get the application info")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}
@ -90,7 +91,7 @@ ServerSettings::_GetUserAgentVersionString()
BFile file(&info.ref, B_READ_ONLY);
if (file.InitCheck() != B_OK) {
fprintf(stderr, "Unable to access the application info file\n");
HDERROR("Unable to access the application info file")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}
@ -100,7 +101,7 @@ ServerSettings::_GetUserAgentVersionString()
if (appFileInfo.GetVersionInfo(
&versionInfo, B_APP_VERSION_KIND) != B_OK) {
fprintf(stderr, "Unable to establish the application version\n");
HDERROR("Unable to establish the application version")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "StandardMetaDataJsonEventListener.h"
#include "stdio.h"
#include "Logger.h"
#define KEY_CREATE_TIMESTAMP "createTimestamp"
@ -384,8 +384,8 @@ void
StandardMetaDataJsonEventListener::HandleError(status_t status, int32 line,
const char* message)
{
fprintf(stderr, "an error has arisen processing the standard "
"meta data; %s\n", message);
HDERROR("an error has arisen processing the standard "
"meta data; %s", message)
fErrorStatus = status;
}

View File

@ -62,8 +62,8 @@ UserDetailVerifierProcess::RunInternal()
break;
case B_OK:
if (!userDetail.Agreement().IsLatest()) {
printf("! the user has not agreed to the latest user usage"
" conditions.\n");
HDINFO("the user has not agreed to the latest user usage"
" conditions.")
fListener->UserUsageConditionsNotLatest(userDetail);
}
break;
@ -80,14 +80,14 @@ bool
UserDetailVerifierProcess::_ShouldVerify()
{
if (!ServerHelper::IsNetworkAvailable()) {
printf("no network --> will not verify user\n");
HDINFO("no network --> will not verify user")
return false;
}
{
AutoLocker<BLocker> locker(fModel->Lock());
if (fModel->Nickname().IsEmpty()) {
printf("no nickname --> will not verify user\n");
HDINFO("no nickname --> will not verify user");
return false;
}
}
@ -105,8 +105,8 @@ UserDetailVerifierProcess::_TryFetchUserDetail(UserDetail& userDetail)
result = interface.RetrieveCurrentUserDetail(userDetailResponse);
if (result != B_OK) {
printf("a problem has arisen retrieving the current user detail: %s\n",
strerror(result));
HDERROR("a problem has arisen retrieving the current user detail: %s",
strerror(result))
}
if (result == B_OK) {
@ -118,9 +118,9 @@ UserDetailVerifierProcess::_TryFetchUserDetail(UserDetail& userDetail)
result = B_PERMISSION_DENIED;
break;
default:
printf("! a problem has arisen retrieving the current user "
"detail for user [%s]: jrpc error code %" B_PRId32 "\n",
fModel->Nickname().String(), errorCode);
HDERROR("a problem has arisen retrieving the current user "
"detail for user [%s]: jrpc error code %" B_PRId32 "",
fModel->Nickname().String(), errorCode)
result = B_ERROR;
break;
}
@ -134,7 +134,7 @@ UserDetailVerifierProcess::_TryFetchUserDetail(UserDetail& userDetail)
result = interface.UnpackUserDetail(userDetailResponse, userDetail);
if (result != B_OK)
printf("! it was not possible to unpack the user details.\n");
HDERROR("it was not possible to unpack the user details.")
}
return result;

View File

@ -6,8 +6,6 @@
#include "WebAppInterface.h"
#include <stdio.h>
#include <Application.h>
#include <HttpHeaders.h>
#include <HttpRequest.h>
@ -35,10 +33,9 @@
class ProtocolListener : public BUrlProtocolListener {
public:
ProtocolListener(bool traceLogging)
ProtocolListener()
:
fDownloadIO(NULL),
fTraceLogging(traceLogging)
fDownloadIO(NULL)
{
}
@ -86,8 +83,7 @@ public:
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
if (fTraceLogging)
printf("jrpc: %s\n", text);
HDTRACE("jrpc: %s", text)
}
void SetDownloadIO(BDataIO* downloadIO)
@ -97,7 +93,6 @@ public:
private:
BDataIO* fDownloadIO;
bool fTraceLogging;
};
@ -342,7 +337,7 @@ WebAppInterface::UnpackUserDetail(BMessage& responseEnvelopeMessage,
"result", &resultMessage);
if (result != B_OK) {
fprintf(stderr, "bad response envelope missing 'result' entry\n");
HDERROR("bad response envelope missing 'result' entry");
return result;
}
@ -405,7 +400,7 @@ WebAppInterface::RetrieveUserUsageConditions(const BString& code,
BMessage resultMessage;
if (responseEnvelopeMessage.FindMessage("result", &resultMessage) != B_OK) {
fprintf(stderr, "bad response envelope missing 'result' entry\n");
HDERROR("bad response envelope missing 'result' entry")
return B_BAD_DATA;
}
@ -414,10 +409,10 @@ WebAppInterface::RetrieveUserUsageConditions(const BString& code,
BString copyMarkdown;
if ( (resultMessage.FindString("code", &metaDataCode) != B_OK)
|| (resultMessage.FindDouble(
"minimumAge", &metaDataMinimumAge) != B_OK) ) {
printf("unexpected response from server with missing user usage "
"conditions data\n");
|| (resultMessage.FindDouble(
"minimumAge", &metaDataMinimumAge) != B_OK) ) {
HDERROR("unexpected response from server with missing user usage "
"conditions data")
return B_BAD_DATA;
}
@ -811,48 +806,40 @@ WebAppInterface::_SendJsonRequest(const char* domain,
size_t requestDataSize, uint32 flags, BMessage& reply) const
{
if (requestDataSize == 0) {
if (Logger::IsInfoEnabled())
printf("jrpc; empty request payload\n");
HDINFO("jrpc; empty request payload")
return B_ERROR;
}
if (!ServerHelper::IsNetworkAvailable()) {
if (Logger::IsDebugEnabled()) {
printf("jrpc; dropping request to ...[%s] as network is not "
"available\n", domain);
}
HDDEBUG("jrpc; dropping request to ...[%s] as network is not"
" available", domain)
delete requestData;
return HD_NETWORK_INACCESSIBLE;
}
if (ServerSettings::IsClientTooOld()) {
if (Logger::IsDebugEnabled()) {
printf("jrpc; dropping request to ...[%s] as client is too "
"old\n", domain);
}
HDDEBUG("jrpc; dropping request to ...[%s] as client is too old",
domain)
delete requestData;
return HD_CLIENT_TOO_OLD;
}
BUrl url = ServerSettings::CreateFullUrl(BString("/__api/v1/") << domain);
bool isSecure = url.Protocol() == "https";
if (Logger::IsDebugEnabled()) {
printf("jrpc; will make request to [%s]\n",
url.UrlString().String());
}
HDDEBUG("jrpc; will make request to [%s]", url.UrlString().String())
// If the request payload is logged then it must be copied to local memory
// from the stream. This then requires that the request data is then
// delivered from memory.
if (Logger::IsTraceEnabled()) {
HDLOGPREFIX(LOG_LEVEL_TRACE)
printf("jrpc request; ");
_LogPayload(requestData, requestDataSize);
printf("\n");
}
ProtocolListener listener(Logger::IsTraceEnabled());
ProtocolListener listener;
BUrlContext context;
BHttpHeaders headers;
@ -886,10 +873,8 @@ WebAppInterface::_SendJsonRequest(const char* domain,
int32 statusCode = result.StatusCode();
if (Logger::IsDebugEnabled()) {
printf("jrpc; did receive http-status [%" B_PRId32 "] "
"from [%s]\n", statusCode, url.UrlString().String());
}
HDDEBUG("jrpc; did receive http-status [%" B_PRId32 "] from [%s]",
statusCode, url.UrlString().String())
switch (statusCode) {
case B_HTTP_STATUS_OK:
@ -900,14 +885,15 @@ WebAppInterface::_SendJsonRequest(const char* domain,
return HD_CLIENT_TOO_OLD;
default:
printf("jrpc request to endpoint [.../%s] failed with http "
"status [%" B_PRId32 "]\n", domain, statusCode);
HDERROR("jrpc request to endpoint [.../%s] failed with http "
"status [%" B_PRId32 "]\n", domain, statusCode)
return B_ERROR;
}
replyData.Seek(0, SEEK_SET);
if (Logger::IsTraceEnabled()) {
HDLOGPREFIX(LOG_LEVEL_TRACE)
printf("jrpc response; ");
_LogPayload(&replyData, replyData.BufferLength());
printf("\n");
@ -920,7 +906,7 @@ WebAppInterface::_SendJsonRequest(const char* domain,
if (Logger::IsTraceEnabled() && status == B_BAD_DATA) {
BString resultString(static_cast<const char *>(replyData.Buffer()),
replyData.BufferLength());
printf("Parser choked on JSON:\n%s\n", resultString.String());
HDERROR("Parser choked on JSON:\n%s", resultString.String())
}
return status;
}
@ -946,7 +932,7 @@ WebAppInterface::_SendRawGetRequest(const BString urlPathComponents,
BUrl url = ServerSettings::CreateFullUrl(urlPathComponents);
bool isSecure = url.Protocol() == "https";
ProtocolListener listener(Logger::IsTraceEnabled());
ProtocolListener listener;
listener.SetDownloadIO(stream);
BHttpHeaders headers;
@ -967,8 +953,8 @@ WebAppInterface::_SendRawGetRequest(const BString urlPathComponents,
if (statusCode == 200)
return B_OK;
fprintf(stderr, "failed to get data from '%s': %" B_PRIi32 "\n",
url.UrlString().String(), statusCode);
HDERROR("failed to get data from '%s': %" B_PRIi32 "",
url.UrlString().String(), statusCode)
return B_ERROR;
}
@ -983,7 +969,7 @@ WebAppInterface::_LogPayload(BPositionIO* requestData, size_t size)
size = LOG_PAYLOAD_LIMIT;
if (B_OK != requestData->ReadExactly(buffer, size)) {
printf("jrpc; error logging payload\n");
printf("jrpc; error logging payload");
} else {
for (uint32 i = 0; i < size; i++) {
bool esc = buffer[i] > 126 ||

View File

@ -1,12 +1,11 @@
/*
* Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TarArchiveHeader.h"
#include <stdio.h>
#include "Logger.h"
#define OFFSET_FILENAME 0
#define OFFSET_LENGTH 124
@ -116,9 +115,9 @@ TarArchiveHeader::CreateFromBlock(const unsigned char* block)
LENGTH_CHECKSUM);
if(actualChecksum != expectedChecksum) {
fprintf(stderr, "tar archive header has bad checksum;"
"expected %" B_PRIu32 " actual %" B_PRIu32 "\n",
expectedChecksum, actualChecksum);
HDERROR("tar archive header has bad checksum;"
"expected %" B_PRIu32 " actual %" B_PRIu32,
expectedChecksum, actualChecksum)
} else {
return new TarArchiveHeader(
_ReadString(&block[OFFSET_FILENAME], LENGTH_FILENAME),

View File

@ -1,13 +1,11 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TarArchiveService.h"
#include <stdio.h>
#include <Directory.h>
#include <File.h>
#include <StringList.h>
@ -28,7 +26,7 @@ TarArchiveService::Unpack(BDataIO& tarDataIo, BPath& targetDirectory,
status_t result = B_OK;
uint32_t count_items_read = 0;
fprintf(stdout, "will unpack to [%s]\n", targetDirectory.Path());
HDINFO("will unpack to [%s]", targetDirectory.Path())
memset(zero_buffer, 0, sizeof zero_buffer);
@ -39,15 +37,14 @@ TarArchiveService::Unpack(BDataIO& tarDataIo, BPath& targetDirectory,
count_items_read++;
if (0 == memcmp(zero_buffer, buffer, sizeof zero_buffer)) {
if (Logger::IsDebugEnabled())
printf("detected end of tar-ball\n");
HDDEBUG("detected end of tar-ball")
return B_OK; // end of tar-ball.
} else {
TarArchiveHeader* header = TarArchiveHeader::CreateFromBlock(
buffer);
if (NULL == header) {
fprintf(stderr, "unable to parse a tar header\n");
HDERROR("unable to parse a tar header")
result = B_ERROR;
}
@ -58,11 +55,10 @@ TarArchiveService::Unpack(BDataIO& tarDataIo, BPath& targetDirectory,
}
}
fprintf(stdout, "did unpack %d tar items\n", count_items_read);
HDERROR("did unpack %d tar items", count_items_read)
if (B_OK != result) {
fprintf(stdout, "error occurred unpacking tar items; %s\n",
strerror(result));
HDERROR("error occurred unpacking tar items; %s", strerror(result))
}
return result;
@ -83,7 +79,7 @@ TarArchiveService::_EnsurePathToTarItemFile(
BString component = components.StringAt(i);
if (_ValidatePathComponent(component) != B_OK) {
fprintf(stdout, "malformed component; [%s]\n", component.String());
HDERROR("malformed component; [%s]", component.String())
return B_ERROR;
}
}
@ -112,10 +108,8 @@ TarArchiveService::_UnpackItem(BDataIO& tarDataIo,
BString entryFileName = header.GetFileName();
uint32 entryLength = header.GetLength();
if (Logger::IsDebugEnabled()) {
fprintf(stdout, "will unpack item [%s] length [%" B_PRIu32 "]b\n",
entryFileName.String(), entryLength);
}
HDDEBUG("will unpack item [%s] length [%" B_PRIu32 "]b",
entryFileName.String(), entryLength)
// if the path ends in "/" then it is a directory and there's no need to
// unpack it although if there is a length, it will need to be skipped.
@ -172,8 +166,7 @@ TarArchiveService::_UnpackItemData(BDataIO& tarDataIo,
}
if (result != B_OK)
fprintf(stdout, "unable to unpack item data to; [%s]\n",
targetFilePath.Path());
HDERROR("unable to unpack item data to; [%s]", targetFilePath.Path())
return result;
}

View File

@ -530,8 +530,9 @@ App::_CheckIsFirstRun()
bool exists = false;
status_t status = StorageUtils::LocalWorkingFilesPath("testfile.txt",
testFilePath, false);
if (status != B_OK)
printf("! unable to establish the location of the test file\n");
if (status != B_OK) {
HDERROR("unable to establish the location of the test file")
}
else
status = StorageUtils::ExistsObject(testFilePath, &exists, NULL, NULL);
return !exists;

View File

@ -8,7 +8,6 @@
#include "FeaturedPackagesView.h"
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <Bitmap.h>
@ -23,6 +22,7 @@
#include "BitmapView.h"
#include "HaikuDepotConstants.h"
#include "Logger.h"
#include "MainWindow.h"
#include "MarkupTextView.h"
#include "MessagePackageListener.h"
@ -81,8 +81,9 @@ public:
case MSG_UPDATE_PACKAGE:
{
BString name;
if (message->FindString("name", &name) != B_OK)
printf("expected 'name' key on package update message\n");
if (message->FindString("name", &name) != B_OK) {
HDINFO("expected 'name' key on package update message")
}
else
_HandleUpdatePackage(name);
break;
@ -653,7 +654,7 @@ FeaturedPackagesView::RemovePackage(const PackageInfoRef& package)
void
FeaturedPackagesView::Clear()
{
printf("did clear the featured packages view\n");
HDINFO("did clear the featured packages view")
fPackagesView->Clear();
_AdjustViews();
}

View File

@ -302,7 +302,7 @@ MainWindow::MessageReceived(BMessage* message)
if (message->FindInt64(KEY_ERROR_STATUS, &errorStatus64) == B_OK)
_BulkLoadCompleteReceived((status_t) errorStatus64);
else
printf("! expected [%s] value in message\n", KEY_ERROR_STATUS);
HDERROR("expected [%s] value in message", KEY_ERROR_STATUS)
break;
}
case B_SIMPLE_DATA:
@ -412,11 +412,9 @@ MainWindow::MessageReceived(BMessage* message)
if (fPackageInfoView->Package()->Name() == name) {
_PopulatePackageAsync(true);
} else {
if (Logger::IsDebugEnabled()) {
printf("pkg [%s] is updated on the server, but is "
"not selected so will not be updated.\n",
name.String());
}
HDDEBUG("pkg [%s] is updated on the server, but is "
"not selected so will not be updated.",
name.String())
}
}
break;
@ -823,8 +821,7 @@ MainWindow::_AdoptModelControls()
void
MainWindow::_AdoptModel()
{
if (Logger::IsTraceEnabled())
printf("adopting model to main window ui\n");
HDTRACE("adopting model to main window ui")
if (fSinglePackageMode)
return;
@ -1039,10 +1036,8 @@ MainWindow::_PopulatePackageAsync(bool forcePopulate)
}
release_sem_etc(fPackageToPopulateSem, 1, 0);
if (Logger::IsDebugEnabled()) {
printf("pkg [%s] will be updated from the server.\n",
fPackageToPopulate->Name().String());
}
HDDEBUG("pkg [%s] will be updated from the server.",
fPackageToPopulate->Name().String())
}
@ -1075,10 +1070,7 @@ MainWindow::_PopulatePackageWorker(void* arg)
window->fModel.PopulatePackage(package, populateFlags);
if (Logger::IsDebugEnabled()) {
printf("populating package [%s]\n",
package->Name().String());
}
HDDEBUG("populating package [%s]", package->Name().String())
}
}
@ -1184,22 +1176,19 @@ MainWindow::_SelectedPackageHasWebAppRepositoryCode()
const BString depotName = package->DepotName();
if (depotName.IsEmpty()) {
if (Logger::IsDebugEnabled()) {
printf("the package [%s] has no depot name\n",
package->Name().String());
}
HDDEBUG("the package [%s] has no depot name", package->Name().String())
} else {
const DepotInfo* depot = fModel.DepotForName(depotName);
if (depot == NULL) {
printf("the depot [%s] was not able to be found\n",
depotName.String());
HDINFO("the depot [%s] was not able to be found",
depotName.String())
} else {
BString repositoryCode = depot->WebAppRepositoryCode();
if (repositoryCode.IsEmpty()) {
printf("the depot [%s] has no web app repository code\n",
depotName.String());
HDINFO("the depot [%s] has no web app repository code",
depotName.String())
} else {
return true;
}
@ -1312,7 +1301,7 @@ MainWindow::UserUsageConditionsNotLatest(const UserDetail& userDetail)
BMessage detailsMessage;
if (userDetail.Archive(&detailsMessage, true) != B_OK
|| message.AddMessage("userDetail", &detailsMessage) != B_OK) {
printf("!! unable to archive the user detail into a message\n");
HDERROR("unable to archive the user detail into a message")
}
else
BMessenger(this).SendMessage(&message);
@ -1337,18 +1326,14 @@ MainWindow::_AddProcessCoordinator(ProcessCoordinator* item)
if (fCoordinator.Get() == NULL) {
if (acquire_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to acquire the process coordinator sem");
if (Logger::IsInfoEnabled()) {
printf("adding and starting a process coordinator [%s]\n",
item->Name().String());
}
HDINFO("adding and starting a process coordinator [%s]",
item->Name().String())
fCoordinator = BReference<ProcessCoordinator>(item);
fCoordinator->Start();
}
else {
if (Logger::IsInfoEnabled()) {
printf("adding process coordinator [%s] to the queue\n",
item->Name().String());
}
HDINFO("adding process coordinator [%s] to the queue",
item->Name().String());
fCoordinatorQueue.push(item);
}
}
@ -1374,18 +1359,16 @@ MainWindow::_SpinUntilProcessCoordinatorComplete()
void
MainWindow::_StopProcessCoordinators()
{
if (Logger::IsInfoEnabled())
printf("will stop all process coordinators\n");
HDINFO("will stop all process coordinators")
{
AutoLocker<BLocker> lock(&fCoordinatorLock);
while (!fCoordinatorQueue.empty()) {
BReference<ProcessCoordinator> processCoordinator = fCoordinatorQueue.front();
if (Logger::IsInfoEnabled()) {
printf("will drop queued process coordinator [%s]\n",
processCoordinator->Name().String());
}
BReference<ProcessCoordinator> processCoordinator
= fCoordinatorQueue.front();
HDINFO("will drop queued process coordinator [%s]",
processCoordinator->Name().String())
fCoordinatorQueue.pop();
}
@ -1394,13 +1377,11 @@ MainWindow::_StopProcessCoordinators()
}
}
if (Logger::IsInfoEnabled())
printf("will wait until the process coordinator has stopped\n");
HDINFO("will wait until the process coordinator has stopped")
_SpinUntilProcessCoordinatorComplete();
if (Logger::IsInfoEnabled())
printf("did stop all process coordinators\n");
HDINFO("did stop all process coordinators")
}
@ -1419,10 +1400,8 @@ MainWindow::CoordinatorChanged(ProcessCoordinatorState& coordinatorState)
if (!coordinatorState.IsRunning()) {
if (release_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to release the process coordinator sem");
if (Logger::IsInfoEnabled()) {
printf("process coordinator [%s] did complete\n",
fCoordinator->Name().String());
}
HDINFO("process coordinator [%s] did complete",
fCoordinator->Name().String())
// complete the last one that just finished
BMessage* message = fCoordinator->Message();
@ -1442,10 +1421,8 @@ MainWindow::CoordinatorChanged(ProcessCoordinatorState& coordinatorState)
if (acquire_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to acquire the process coordinator sem");
fCoordinator = fCoordinatorQueue.front();
if (Logger::IsInfoEnabled()) {
printf("starting next process coordinator [%s]\n",
fCoordinator->Name().String());
}
HDINFO("starting next process coordinator [%s]",
fCoordinator->Name().String());
fCoordinatorQueue.pop();
fCoordinator->Start();
}
@ -1459,8 +1436,7 @@ MainWindow::CoordinatorChanged(ProcessCoordinatorState& coordinatorState)
// show the progress to the user.
}
} else {
if (Logger::IsInfoEnabled())
printf("! unknown process coordinator changed\n");
HDINFO("! unknown process coordinator changed")
}
}

View File

@ -21,6 +21,8 @@
#include <StringFormat.h>
#include <StringItem.h>
#include "Logger.h"
#include <package/PackageDefs.h>
#include <package/hpkg/NoErrorOutput.h>
#include <package/hpkg/PackageContentHandler.h>
@ -122,16 +124,11 @@ public:
virtual status_t HandleEntry(BPackageEntry* entry)
{
// printf("HandleEntry(%s/%s)\n",
// entry->Parent() != NULL ? entry->Parent()->Name() : "NULL",
// entry->Name());
if (fListView->LockLooperWithTimeout(1000000) != B_OK)
return B_ERROR;
// Check if we are still supposed to popuplate the list
if (fPackageInfoRef.Get() != fPackageInfoToPopulate) {
// printf("stopping package content population\n");
fListView->UnlockLooper();
return B_ERROR;
}
@ -148,17 +145,14 @@ public:
PackageEntryItem* item = new PackageEntryItem(entry, path);
if (entry->Parent() == NULL) {
// printf(" adding root entry\n");
fListView->AddItem(item);
fLastParentEntry = NULL;
fLastParentItem = NULL;
} else if (entry->Parent() == fLastEntry) {
// printf(" adding to last entry %s\n", fLastEntry->Name());
fListView->AddUnder(item, fLastItem);
fLastParentEntry = fLastEntry;
fLastParentItem = fLastItem;
} else if (entry->Parent() == fLastParentEntry) {
// printf(" adding to last parent %s\n", fLastParentEntry->Name());
fListView->AddUnder(item, fLastParentItem);
} else {
// Not the last parent entry, need to search for the parent
@ -173,7 +167,6 @@ public:
if (listItem->EntryPath() == path) {
fLastParentEntry = entry->Parent();
fLastParentItem = listItem;
// printf(" found parent %s\n", listItem->Text());
fListView->AddUnder(item, listItem);
foundParent = true;
break;
@ -182,8 +175,6 @@ public:
if (!foundParent) {
// NOTE: Should not happen. Just add this entry at the
// root level.
// printf("Did not find parent entry for %s (%s)!\n",
// entry->Name(), entry->Parent()->Name());
fListView->AddItem(item);
fLastParentEntry = NULL;
fLastParentItem = NULL;
@ -391,8 +382,8 @@ PackageContentsView::_PopulatePackageContents(const PackageInfo& package)
return false;
}
} else {
printf("PackageContentsView::_PopulatePackageContents(): "
"unknown install location");
HDINFO("PackageContentsView::_PopulatePackageContents(): "
"unknown install location")
return false;
}
@ -405,9 +396,9 @@ PackageContentsView::_PopulatePackageContents(const PackageInfo& package)
status_t status = reader.Init(packagePath.Path());
if (status != B_OK) {
printf("PackageContentsView::_PopulatePackageContents(): "
"failed to init BPackageReader(%s): %s\n",
packagePath.Path(), strerror(status));
HDINFO("PackageContentsView::_PopulatePackageContents(): "
"failed to init BPackageReader(%s): %s",
packagePath.Path(), strerror(status))
return false;
}
@ -416,8 +407,8 @@ PackageContentsView::_PopulatePackageContents(const PackageInfo& package)
fPackageLock, fPackage);
status = reader.ParseContent(&contentHandler);
if (status != B_OK) {
printf("PackageContentsView::_PopulatePackageContents(): "
"failed parse package contents: %s\n", strerror(status));
HDINFO("PackageContentsView::_PopulatePackageContents(): "
"failed parse package contents: %s", strerror(status))
// NOTE: Do not return false, since it taken to mean this
// is a remote package, but is it not, we simply want to stop
// populating the contents early.

View File

@ -7,7 +7,6 @@
#include "PackageInfoView.h"
#include <algorithm>
#include <stdio.h>
#include <Alert.h>
#include <Autolock.h>
@ -39,6 +38,7 @@
#include "LinkView.h"
#include "LinkedBitmapView.h"
#include "LocaleUtils.h"
#include "Logger.h"
#include "MarkupTextView.h"
#include "MessagePackageListener.h"
#include "PackageActionHandler.h"
@ -624,10 +624,10 @@ private:
= fPackageActionHandler->SchedulePackageActions(actions);
if (result != B_OK) {
fprintf(stderr, "Failed to schedule action: "
"%s '%s': %s\n", action->Label(),
HDERROR("Failed to schedule action: %s '%s': %s",
action->Label(),
action->Package()->Name().String(),
strerror(result));
strerror(result))
BString message(B_TRANSLATE("The package action "
"could not be scheduled: %Error%"));
message.ReplaceAll("%Error%", strerror(result));

View File

@ -24,6 +24,7 @@
#include "HaikuDepotConstants.h"
#include "LanguageMenuUtils.h"
#include "Logger.h"
#include "MarkupParser.h"
#include "RatingView.h"
#include "ServerHelper.h"
@ -530,7 +531,7 @@ RatePackageWindow::_RelayServerDataToUI(BMessage& response)
Unlock();
} else {
fprintf(stderr, "unable to acquire lock to update the ui\n");
HDERROR("unable to acquire lock to update the ui");
}
}
@ -539,7 +540,7 @@ void
RatePackageWindow::_QueryRatingThread()
{
if (!Lock()) {
fprintf(stderr, "rating query: Failed to lock window\n");
HDERROR("rating query: Failed to lock window");
return;
}
@ -552,7 +553,7 @@ RatePackageWindow::_QueryRatingThread()
locker.Unlock();
if (package.Get() == NULL) {
fprintf(stderr, "rating query: No package\n");
HDERROR("rating query: No package");
_SetWorkerThread(-1);
return;
}
@ -566,8 +567,8 @@ RatePackageWindow::_QueryRatingThread()
repositoryCode = depot->WebAppRepositoryCode();
if (repositoryCode.IsEmpty()) {
printf("unable to obtain the repository code for depot; %s\n",
package->DepotName().String());
HDERROR("unable to obtain the repository code for depot; %s",
package->DepotName().String())
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
} else {
status_t status = interface
@ -586,8 +587,7 @@ RatePackageWindow::_QueryRatingThread()
if (info.FindMessage("result", &result) == B_OK) {
_RelayServerDataToUI(result);
} else {
fprintf(stderr, "bad response envelope missing 'result'"
"entry\n");
HDERROR("bad response envelope missing 'result' entry")
ServerHelper::NotifyTransportError(B_BAD_VALUE);
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
}
@ -595,9 +595,9 @@ RatePackageWindow::_QueryRatingThread()
}
case ERROR_CODE_OBJECTNOTFOUND:
// an expected response
fprintf(stderr, "there was no previous rating for this"
HDINFO("there was no previous rating for this"
" user on this version of this package so a new rating"
" will be added.\n");
" will be added.")
break;
default:
ServerHelper::NotifyServerJsonRpcError(info);
@ -605,9 +605,9 @@ RatePackageWindow::_QueryRatingThread()
break;
}
} else {
fprintf(stderr, "an error has arisen communicating with the"
" server to obtain data for an existing rating [%s]\n",
strerror(status));
HDERROR("an error has arisen communicating with the"
" server to obtain data for an existing rating [%s]",
strerror(status))
ServerHelper::NotifyTransportError(status);
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
}
@ -630,7 +630,7 @@ void
RatePackageWindow::_SendRatingThread()
{
if (!Lock()) {
fprintf(stderr, "upload rating: Failed to lock window\n");
HDERROR("upload rating: Failed to lock window")
return;
}
@ -658,9 +658,9 @@ RatePackageWindow::_SendRatingThread()
Unlock();
if (repositoryCode.Length() == 0) {
printf("unable to find the web app repository code for the local "
"depot %s\n",
fPackage->DepotName().String());
HDERROR("unable to find the web app repository code for the local "
"depot %s",
fPackage->DepotName().String())
return;
}
@ -670,13 +670,11 @@ RatePackageWindow::_SendRatingThread()
status_t status;
BMessage info;
if (ratingID.Length() > 0) {
printf("will update the existing user rating [%s]\n",
ratingID.String());
HDINFO("will update the existing user rating [%s]", ratingID.String())
status = interface.UpdateUserRating(ratingID,
languageCode, comment, stability, rating, active, info);
} else {
printf("will create a new user rating for pkg [%s]\n",
package.String());
HDINFO("will create a new user rating for pkg [%s]", package.String())
status = interface.CreateUserRating(package, fPackage->Version(),
architecture, repositoryCode, languageCode, comment, stability,
rating, info);
@ -699,9 +697,9 @@ RatePackageWindow::_SendRatingThread()
break;
}
} else {
fprintf(stderr, "an error has arisen communicating with the"
" server to obtain data for an existing rating [%s]\n",
strerror(status));
HDERROR("an error has arisen communicating with the"
" server to obtain data for an existing rating [%s]",
strerror(status))
ServerHelper::NotifyTransportError(status);
}

View File

@ -1,13 +1,13 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ScreenshotWindow.h"
#include <algorithm>
#include <stdio.h>
#include <Autolock.h>
#include <Catalog.h>
@ -18,6 +18,7 @@
#include "BarberPole.h"
#include "BitmapView.h"
#include "HaikuDepotConstants.h"
#include "Logger.h"
#include "WebAppInterface.h"
@ -253,9 +254,8 @@ ScreenshotWindow::_DownloadThreadEntry(void* data)
void
ScreenshotWindow::_DownloadThread()
{
printf("_DownloadThread()\n");
if (!Lock()) {
printf(" failed to lock screenshot window\n");
HDERROR("failed to lock screenshot window")
return;
}
@ -268,7 +268,7 @@ ScreenshotWindow::_DownloadThread()
Unlock();
if (screenshotInfos.CountItems() == 0) {
printf(" package has no screenshots\n");
HDINFO("package has no screenshots")
return;
}
@ -295,13 +295,13 @@ ScreenshotWindow::_DownloadThread()
messenger.SendMessage(MSG_DOWNLOAD_STOP);
if (status == B_OK && Lock()) {
printf("got screenshot");
HDINFO("got screenshot")
fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer), true);
fScreenshotView->SetBitmap(fScreenshot);
_ResizeToFitAndCenter();
Unlock();
} else {
printf(" failed to download screenshot\n");
HDERROR("failed to download screenshot")
}
}

View File

@ -211,8 +211,8 @@ ToLatestUserUsageConditionsWindow::QuitRequested()
if (fWorkerThread >= 0) {
if (Logger::IsDebugEnabled())
printf("quit requested while worker thread is operating -- will "
"try again once the worker thread has completed\n");
HDINFO("quit requested while worker thread is operating -- will "
"try again once the worker thread has completed")
fQuitRequestedDuringWorkerThread = true;
return false;
}

View File

@ -8,7 +8,6 @@
#include <algorithm>
#include <ctype.h>
#include <stdio.h>
#include <mail_encoding.h>
@ -158,8 +157,8 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model)
languagesMenu);
languagesMenu->SetTargetForItems(this);
printf("using preferred language code [%s]\n",
fPreferredLanguageCode.String());
HDINFO("using preferred language code [%s]",
fPreferredLanguageCode.String())
LanguageMenuUtils::MarkLanguageInMenu(fPreferredLanguageCode,
languagesMenu);
}
@ -299,7 +298,7 @@ UserLoginWindow::MessageReceived(BMessage* message)
}
case MSG_CREATE_ACCOUNT_SETUP_ERROR:
printf("failed to setup for account setup - window must quit\n");
HDERROR("failed to setup for account setup - window must quit")
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
break;
@ -371,8 +370,8 @@ UserLoginWindow::QuitRequested()
if (fWorkerThread >= 0) {
if (Logger::IsDebugEnabled())
printf("quit requested while worker thread is operating -- will "
"try again once the worker thread has completed\n");
HDINFO("quit requested while worker thread is operating -- will "
"try again once the worker thread has completed")
fQuitRequestedDuringWorkerThread = true;
return false;
}
@ -531,9 +530,9 @@ UserLoginWindow::_AuthenticateThread(UserCredentials& userCredentials)
if (Logger::IsDebugEnabled()) {
if (token.IsEmpty())
printf("authentication failed\n");
HDINFO("authentication failed")
else
printf("authentication successful\n");
HDINFO("authentication successful")
}
BMessenger messenger(this);
@ -751,9 +750,8 @@ UserLoginWindow::_CreateAccountSetupThreadEntry(void* data)
}
}
if (result == B_OK) {
if (Logger::IsDebugEnabled())
printf("successfully completed collection of create account "
"data from the server in background thread\n");
HDDEBUG("successfully completed collection of create account "
"data from the server in background thread")
messenger.SendMessage(&message);
} else {
debugger("unable to configure the "
@ -887,9 +885,7 @@ UserLoginWindow::_UnpackCaptcha(BMessage& responsePayload, Captcha& captcha)
void
UserLoginWindow::_HandleCreateAccountSetupSuccess(BMessage* message)
{
if (Logger::IsDebugEnabled())
printf("handling account setup success\n");
HDDEBUG("handling account setup success")
BMessage captchaMessage;
BMessage userUsageConditionsMessage;
@ -909,8 +905,7 @@ UserLoginWindow::_HandleCreateAccountSetupSuccess(BMessage* message)
void
UserLoginWindow::_SetCaptcha(Captcha* captcha)
{
if (Logger::IsDebugEnabled())
printf("setting captcha\n");
HDDEBUG("setting captcha")
if (fCaptcha != NULL)
delete fCaptcha;
fCaptcha = captcha;
@ -936,8 +931,7 @@ void
UserLoginWindow::_SetUserUsageConditions(
UserUsageConditions* userUsageConditions)
{
if (Logger::IsDebugEnabled())
printf("setting user usage conditions\n");
HDDEBUG("setting user usage conditions")
if (fUserUsageConditions != NULL)
delete fUserUsageConditions;
fUserUsageConditions = userUsageConditions;
@ -1275,8 +1269,8 @@ UserLoginWindow::_CreateAccountThread(CreateUserDetail* detail)
BString debugString;
_ValidationFailuresToString(validationFailures,
debugString);
printf("create account validation issues; %s\n",
debugString.String());
HDDEBUG("create account validation issues; %s",
debugString.String())
}
BMessage validationFailuresMessage;
validationFailures.Archive(&validationFailuresMessage);

View File

@ -215,10 +215,8 @@ UserUsageConditionsWindow::QuitRequested()
if (fWorkerThread == -1)
return true;
if (Logger::IsInfoEnabled()) {
fprintf(stderr, "unable to quit when the user usage "
"conditions window is still fetching data\n");
}
HDINFO("unable to quit when the user usage "
"conditions window is still fetching data")
return false;
}
@ -360,25 +358,21 @@ UserUsageConditionsWindow::_FetchUserUsageConditionsCodeForUserPerform(
break;
}
} else {
fprintf(stderr, "an error has arisen communicating with the"
HDERROR("an error has arisen communicating with the"
" server to obtain data for a user's user usage conditions"
" [%s]\n", strerror(result));
" [%s]", strerror(result))
ServerHelper::NotifyTransportError(result);
}
if (result == B_OK) {
BString userUsageConditionsCode = userDetail.Agreement().Code();
if (Logger::IsDebugEnabled()) {
printf("the user [%s] has agreed to uuc [%s]\n",
interface.Nickname().String(),
userUsageConditionsCode.String());
}
HDDEBUG("the user [%s] has agreed to uuc [%s]",
interface.Nickname().String(),
userUsageConditionsCode.String())
code.SetTo(userUsageConditionsCode);
} else {
if (Logger::IsDebugEnabled()) {
printf("unable to get details of the user [%s]\n",
interface.Nickname().String());
}
HDDEBUG("unable to get details of the user [%s]",
interface.Nickname().String())
}
return result;
@ -400,8 +394,7 @@ void
UserUsageConditionsWindow::_SetWorkerThread(thread_id thread)
{
if (!Lock()) {
if (Logger::IsInfoEnabled())
fprintf(stderr, "failed to lock window\n");
HDERROR("failed to lock window")
} else {
fWorkerThread = thread;
Unlock();

View File

@ -1,12 +1,12 @@
/*
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "SharedBitmap.h"
#include <algorithm>
#include <stdio.h>
#include <Application.h>
#include <Bitmap.h>
@ -17,6 +17,8 @@
#include <Resources.h>
#include <TranslationUtils.h>
#include "Logger.h"
#include "support.h"
@ -98,8 +100,8 @@ SharedBitmap::SharedBitmap(BPositionIO& data)
} else
fSize = 0;
} else {
fprintf(stderr, "SharedBitmap(): Stream too large: %" B_PRIi64
", max: %" B_PRIi64 "\n", fSize, kMaxSize);
HDERROR("SharedBitmap(): Stream too large: %" B_PRIi64
", max: %" B_PRIi64, fSize, kMaxSize)
}
fBitmap[0] = NULL;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "LanguageMenuUtils.h"
@ -23,8 +23,8 @@
LanguageMenuUtils::AddLanguagesToMenu(
const LanguageList& languages, BMenu* menu)
{
if (languages.IsEmpty() && Logger::IsInfoEnabled())
printf("there are no languages defined\n");
if (languages.IsEmpty())
HDINFO("there are no languages defined")
int32 addedPopular = LanguageMenuUtils::_AddLanguagesToMenu(
languages, menu, true);
@ -35,11 +35,9 @@ LanguageMenuUtils::AddLanguagesToMenu(
int32 addedNonPopular = LanguageMenuUtils::_AddLanguagesToMenu(
languages, menu, false);
if (Logger::IsDebugEnabled()) {
printf("did add %" B_PRId32 " popular languages and %" B_PRId32
" non-popular languages to a menu\n", addedPopular,
addedNonPopular);
}
HDDEBUG("did add %" B_PRId32 " popular languages and %" B_PRId32
" non-popular languages to a menu", addedPopular,
addedNonPopular)
}
@ -56,8 +54,8 @@ LanguageMenuUtils::MarkLanguageInMenu(
languageCode, menu);
if (index == -1) {
printf("unable to find the language [%s] in the menu\n",
languageCode.String());
HDINFO("unable to find the language [%s] in the menu",
languageCode.String())
menu->ItemAt(0)->SetMarked(true);
}
else

View File

@ -5,8 +5,8 @@
#include "StorageUtils.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <Directory.h>
#include <File.h>
@ -86,13 +86,9 @@ StorageUtils::RemoveDirectoryContents(BPath& path)
RemoveDirectoryContents(directoryEntryPath);
if (remove(directoryEntryPath.Path()) == 0) {
if (Logger::IsDebugEnabled()) {
fprintf(stdout, "did delete [%s]\n",
directoryEntryPath.Path());
}
HDDEBUG("did delete [%s]", directoryEntryPath.Path())
} else {
fprintf(stderr, "unable to delete [%s]\n",
directoryEntryPath.Path());
HDERROR("unable to delete [%s]", directoryEntryPath.Path())
result = B_ERROR;
}
}
@ -167,17 +163,13 @@ StorageUtils::CheckCanWriteTo(const BPath& path)
result = ExistsObject(path, &exists, NULL, NULL);
if (result == B_OK && exists) {
if (Logger::IsTraceEnabled()) {
printf("an object exists at the candidate path "
"[%s] - it will be deleted\n", path.Path());
}
HDTRACE("an object exists at the candidate path "
"[%s] - it will be deleted", path.Path())
if (remove(path.Path()) == 0) {
if (Logger::IsTraceEnabled()) {
printf("did delete the candidate file [%s]\n", path.Path());
}
HDTRACE("did delete the candidate file [%s]", path.Path())
} else {
printf("unable to delete the candidate file [%s]\n", path.Path());
HDERROR("unable to delete the candidate file [%s]", path.Path())
result = B_ERROR;
}
}
@ -185,8 +177,8 @@ StorageUtils::CheckCanWriteTo(const BPath& path)
if (result == B_OK) {
BFile file(path.Path(), O_WRONLY | O_CREAT);
if (file.Write(buffer, 16) != 16) {
printf("unable to write test data to candidate file [%s]\n",
path.Path());
HDERROR("unable to write test data to candidate file [%s]",
path.Path())
result = B_ERROR;
}
}
@ -195,15 +187,15 @@ StorageUtils::CheckCanWriteTo(const BPath& path)
BFile file(path.Path(), O_RDONLY);
uint8 readBuffer[16];
if (file.Read(readBuffer, 16) != 16) {
printf("unable to read test data from candidate file [%s]\n",
path.Path());
HDERROR("unable to read test data from candidate file [%s]",
path.Path())
result = B_ERROR;
}
for (int i = 0; result == B_OK && i < 16; i++) {
if (readBuffer[i] != buffer[i]) {
printf("mismatched read..write check on candidate file [%s]\n",
path.Path());
HDERROR("mismatched read..write check on candidate file [%s]",
path.Path())
result = B_ERROR;
}
}
@ -245,8 +237,8 @@ StorageUtils::LocalWorkingFilesPath(const BString leaf, BPath& path,
path.SetTo(resultPath.Path());
else {
path.Unset();
fprintf(stdout, "unable to find the user cache file for "
"[%s] data; %s\n", leaf.String(), strerror(result));
HDERROR("unable to find the user cache file for "
"[%s] data; %s", leaf.String(), strerror(result))
}
return result;
@ -280,8 +272,8 @@ StorageUtils::LocalWorkingDirectoryPath(const BString leaf, BPath& path,
path.SetTo(resultPath.Path());
else {
path.Unset();
fprintf(stdout, "unable to find the user cache directory for "
"[%s] data; %s\n", leaf.String(), strerror(result));
HDERROR("unable to find the user cache directory for "
"[%s] data; %s", leaf.String(), strerror(result))
}
return result;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -8,8 +8,7 @@
#include <File.h>
#include <HttpRequest.h>
#include <stdio.h>
#include "Logger.h"
ToFileUrlProtocolListener::ToFileUrlProtocolListener(BPath path,
BString traceLoggingIdentifier, bool traceLogging)
@ -59,8 +58,8 @@ ToFileUrlProtocolListener::HeadersReceived(BUrlRequest* caller,
int32 statusCode = httpResult.StatusCode();
if (!BHttpRequest::IsSuccessStatusCode(statusCode)) {
fprintf(stdout, "received http status %" B_PRId32
" --> will not store download to file\n", statusCode);
HDINFO("received http status %" B_PRId32
" --> will not store download to file", statusCode)
fShouldDownload = false;
}
@ -84,7 +83,7 @@ ToFileUrlProtocolListener::DataReceived(BUrlRequest* caller, const char* data,
} while (remaining > 0 && written > 0);
if (remaining > 0)
fprintf(stdout, "unable to write all of the data to the file\n");
HDERROR("unable to write all of the data to the file")
}
}
@ -113,10 +112,7 @@ void
ToFileUrlProtocolListener::DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
if (fTraceLogging) {
fprintf(stdout, "url->file <%s>; %s\n",
fTraceLoggingIdentifier.String(), text);
}
HDTRACE("url->file <%s>; %s", fTraceLoggingIdentifier.String(), text)
}