HaikuDepot: Better Logging of Cache File Creation

A user has reported having some problems around
initial use of HaikuDepot and this seems to be
related to setup of the directories etc... at
start time.  This change should improve the
logging so that it is easier to identify the
cause.  Also some additional locking has been
introduced as there might be a problem where two
threads are creating the same directory at the
same time.

Relates to #15493

Change-Id: I4cbfda7c2ce87b8509ceb78788b7995ee3185050
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1980
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Andrew Lindesay
2019-12-08 09:43:20 +00:00
committed by Adrien Destugues
parent 4de612c9b5
commit 041bbff9b0
5 changed files with 54 additions and 40 deletions
+50 -40
View File
@@ -850,24 +850,30 @@ Model::SetAuthorization(const BString& nickname, const BString& passwordClear,
status_t status_t
Model::_LocalDataPath(const BString leaf, BPath& path) const Model::_LocalDataPath(const BString leaf, BPath& path) const
{ {
BString leafAssembled(leaf); BPath resultPath;
leafAssembled.ReplaceAll("%languageCode%", status_t result = B_OK;
LanguageModel().PreferredLanguage().Code());
BPath repoDataPath; if (result == B_OK)
result = find_directory(B_USER_CACHE_DIRECTORY, &resultPath);
if (find_directory(B_USER_CACHE_DIRECTORY, &repoDataPath) == B_OK if (result == B_OK)
&& repoDataPath.Append("HaikuDepot") == B_OK result = resultPath.Append("HaikuDepot");
&& create_directory(repoDataPath.Path(), 0777) == B_OK
&& repoDataPath.Append(leafAssembled) == B_OK) { if (result == B_OK)
path.SetTo(repoDataPath.Path()); result = create_directory(resultPath.Path(), 0777);
return B_OK;
if (result == B_OK)
result = resultPath.Append(leaf);
if (result == B_OK)
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));
} }
path.Unset(); return result;
fprintf(stdout, "unable to find the user cache file for [%s] data",
leaf.String());
return B_ERROR;
} }
@@ -880,7 +886,10 @@ Model::_LocalDataPath(const BString leaf, BPath& path) const
status_t status_t
Model::DumpExportRepositoryDataPath(BPath& path) const Model::DumpExportRepositoryDataPath(BPath& path) const
{ {
return _LocalDataPath("repository-all_%languageCode%.json.gz", path); BString leaf;
leaf.SetToFormat("repository-all_%s.json.gz",
LanguageModel().PreferredLanguage().Code());
return _LocalDataPath(leaf, path);
} }
@@ -892,7 +901,10 @@ Model::DumpExportRepositoryDataPath(BPath& path) const
status_t status_t
Model::DumpExportReferenceDataPath(BPath& path) const Model::DumpExportReferenceDataPath(BPath& path) const
{ {
return _LocalDataPath("reference-all_%languageCode%.json.gz", path); BString leaf;
leaf.SetToFormat("reference-all_%s.json.gz",
LanguageModel().PreferredLanguage().Code());
return _LocalDataPath(leaf, path);
} }
@@ -900,18 +912,29 @@ status_t
Model::IconStoragePath(BPath& path) const Model::IconStoragePath(BPath& path) const
{ {
BPath iconStoragePath; BPath iconStoragePath;
status_t result = B_OK;
if (find_directory(B_USER_CACHE_DIRECTORY, &iconStoragePath) == B_OK if (result == B_OK)
&& iconStoragePath.Append("HaikuDepot") == B_OK result = find_directory(B_USER_CACHE_DIRECTORY, &iconStoragePath);
&& iconStoragePath.Append("__allicons") == B_OK
&& create_directory(iconStoragePath.Path(), 0777) == B_OK) { if (result == B_OK)
result = iconStoragePath.Append("HaikuDepot");
if (result == B_OK)
result = iconStoragePath.Append("__allicons");
if (result == B_OK)
result = create_directory(iconStoragePath.Path(), 0777);
if (result == B_OK)
path.SetTo(iconStoragePath.Path()); path.SetTo(iconStoragePath.Path());
return B_OK; else {
path.Unset();
fprintf(stdout, "unable to find the user cache directory for "
"icons; %s\n", strerror(result));
} }
path.Unset(); return result;
fprintf(stdout, "unable to find the user cache directory for icons");
return B_ERROR;
} }
@@ -919,23 +942,10 @@ status_t
Model::DumpExportPkgDataPath(BPath& path, Model::DumpExportPkgDataPath(BPath& path,
const BString& repositorySourceCode) const const BString& repositorySourceCode) const
{ {
BPath repoDataPath; BString leaf;
BString leafName; leaf.SetToFormat("pkg-all-%s-%s.json.gz", repositorySourceCode.String(),
leafName.SetToFormat("pkg-all-%s-%s.json.gz", repositorySourceCode.String(),
LanguageModel().PreferredLanguage().Code()); LanguageModel().PreferredLanguage().Code());
return _LocalDataPath(leaf, path);
if (find_directory(B_USER_CACHE_DIRECTORY, &repoDataPath) == B_OK
&& repoDataPath.Append("HaikuDepot") == B_OK
&& create_directory(repoDataPath.Path(), 0777) == B_OK
&& repoDataPath.Append(leafName.String()) == B_OK) {
path.SetTo(repoDataPath.Path());
return B_OK;
}
path.Unset();
fprintf(stdout, "unable to find the user cache file for pkgs' data");
return B_ERROR;
} }
@@ -38,6 +38,7 @@ ServerIconExportUpdateProcess::ServerIconExportUpdateProcess(
fModel(model), fModel(model),
fCountIconsSet(0) fCountIconsSet(0)
{ {
AutoLocker<BLocker> locker(fModel->Lock());
if (fModel->IconStoragePath(fLocalIconStoragePath) != B_OK) { if (fModel->IconStoragePath(fLocalIconStoragePath) != B_OK) {
printf("[%s] unable to obtain the path for storing icons\n", Name()); printf("[%s] unable to obtain the path for storing icons\n", Name());
fLocalIconStoragePath.Unset(); fLocalIconStoragePath.Unset();
@@ -284,6 +284,7 @@ ServerPkgDataUpdateProcess::GetLocalPath(BPath& path) const
BString webAppRepositorySourceCode = _DeriveWebAppRepositorySourceCode(); BString webAppRepositorySourceCode = _DeriveWebAppRepositorySourceCode();
if (!webAppRepositorySourceCode.IsEmpty()) { if (!webAppRepositorySourceCode.IsEmpty()) {
AutoLocker<BLocker> locker(fModel->Lock());
return fModel->DumpExportPkgDataPath(path, webAppRepositorySourceCode); return fModel->DumpExportPkgDataPath(path, webAppRepositorySourceCode);
} }
@@ -74,6 +74,7 @@ ServerReferenceDataUpdateProcess::UrlPathComponent()
status_t status_t
ServerReferenceDataUpdateProcess::GetLocalPath(BPath& path) const ServerReferenceDataUpdateProcess::GetLocalPath(BPath& path) const
{ {
AutoLocker<BLocker> locker(fModel->Lock());
return fModel->DumpExportReferenceDataPath(path); return fModel->DumpExportReferenceDataPath(path);
} }
@@ -189,6 +189,7 @@ ServerRepositoryDataUpdateProcess::UrlPathComponent()
status_t status_t
ServerRepositoryDataUpdateProcess::GetLocalPath(BPath& path) const ServerRepositoryDataUpdateProcess::GetLocalPath(BPath& path) const
{ {
AutoLocker<BLocker> locker(fModel->Lock());
return fModel->DumpExportRepositoryDataPath(path); return fModel->DumpExportRepositoryDataPath(path);
} }