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:
committed by
Adrien Destugues
parent
4de612c9b5
commit
041bbff9b0
@@ -850,24 +850,30 @@ Model::SetAuthorization(const BString& nickname, const BString& passwordClear,
|
||||
status_t
|
||||
Model::_LocalDataPath(const BString leaf, BPath& path) const
|
||||
{
|
||||
BString leafAssembled(leaf);
|
||||
leafAssembled.ReplaceAll("%languageCode%",
|
||||
LanguageModel().PreferredLanguage().Code());
|
||||
BPath resultPath;
|
||||
status_t result = B_OK;
|
||||
|
||||
BPath repoDataPath;
|
||||
if (result == B_OK)
|
||||
result = find_directory(B_USER_CACHE_DIRECTORY, &resultPath);
|
||||
|
||||
if (find_directory(B_USER_CACHE_DIRECTORY, &repoDataPath) == B_OK
|
||||
&& repoDataPath.Append("HaikuDepot") == B_OK
|
||||
&& create_directory(repoDataPath.Path(), 0777) == B_OK
|
||||
&& repoDataPath.Append(leafAssembled) == B_OK) {
|
||||
path.SetTo(repoDataPath.Path());
|
||||
return B_OK;
|
||||
if (result == B_OK)
|
||||
result = resultPath.Append("HaikuDepot");
|
||||
|
||||
if (result == B_OK)
|
||||
result = create_directory(resultPath.Path(), 0777);
|
||||
|
||||
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();
|
||||
fprintf(stdout, "unable to find the user cache file for [%s] data",
|
||||
leaf.String());
|
||||
return B_ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -880,7 +886,10 @@ Model::_LocalDataPath(const BString leaf, BPath& path) const
|
||||
status_t
|
||||
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
|
||||
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
|
||||
{
|
||||
BPath iconStoragePath;
|
||||
status_t result = B_OK;
|
||||
|
||||
if (find_directory(B_USER_CACHE_DIRECTORY, &iconStoragePath) == B_OK
|
||||
&& iconStoragePath.Append("HaikuDepot") == B_OK
|
||||
&& iconStoragePath.Append("__allicons") == B_OK
|
||||
&& create_directory(iconStoragePath.Path(), 0777) == B_OK) {
|
||||
if (result == B_OK)
|
||||
result = find_directory(B_USER_CACHE_DIRECTORY, &iconStoragePath);
|
||||
|
||||
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());
|
||||
return B_OK;
|
||||
else {
|
||||
path.Unset();
|
||||
fprintf(stdout, "unable to find the user cache directory for "
|
||||
"icons; %s\n", strerror(result));
|
||||
}
|
||||
|
||||
path.Unset();
|
||||
fprintf(stdout, "unable to find the user cache directory for icons");
|
||||
return B_ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -919,23 +942,10 @@ status_t
|
||||
Model::DumpExportPkgDataPath(BPath& path,
|
||||
const BString& repositorySourceCode) const
|
||||
{
|
||||
BPath repoDataPath;
|
||||
BString leafName;
|
||||
|
||||
leafName.SetToFormat("pkg-all-%s-%s.json.gz", repositorySourceCode.String(),
|
||||
BString leaf;
|
||||
leaf.SetToFormat("pkg-all-%s-%s.json.gz", repositorySourceCode.String(),
|
||||
LanguageModel().PreferredLanguage().Code());
|
||||
|
||||
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;
|
||||
return _LocalDataPath(leaf, path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ ServerIconExportUpdateProcess::ServerIconExportUpdateProcess(
|
||||
fModel(model),
|
||||
fCountIconsSet(0)
|
||||
{
|
||||
AutoLocker<BLocker> locker(fModel->Lock());
|
||||
if (fModel->IconStoragePath(fLocalIconStoragePath) != B_OK) {
|
||||
printf("[%s] unable to obtain the path for storing icons\n", Name());
|
||||
fLocalIconStoragePath.Unset();
|
||||
|
||||
@@ -284,6 +284,7 @@ ServerPkgDataUpdateProcess::GetLocalPath(BPath& path) const
|
||||
BString webAppRepositorySourceCode = _DeriveWebAppRepositorySourceCode();
|
||||
|
||||
if (!webAppRepositorySourceCode.IsEmpty()) {
|
||||
AutoLocker<BLocker> locker(fModel->Lock());
|
||||
return fModel->DumpExportPkgDataPath(path, webAppRepositorySourceCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ ServerReferenceDataUpdateProcess::UrlPathComponent()
|
||||
status_t
|
||||
ServerReferenceDataUpdateProcess::GetLocalPath(BPath& path) const
|
||||
{
|
||||
AutoLocker<BLocker> locker(fModel->Lock());
|
||||
return fModel->DumpExportReferenceDataPath(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ ServerRepositoryDataUpdateProcess::UrlPathComponent()
|
||||
status_t
|
||||
ServerRepositoryDataUpdateProcess::GetLocalPath(BPath& path) const
|
||||
{
|
||||
AutoLocker<BLocker> locker(fModel->Lock());
|
||||
return fModel->DumpExportRepositoryDataPath(path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user