2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "ServerIconExportUpdateProcess.h"
13 #include <support/ZlibCompressionAlgorithm.h>
15 #include "ServerSettings.h"
16 #include "StorageUtils.h"
17 #include "TarArchiveService.h"
20 /*! This constructor will locate the cached data in a standardized location */
22 ServerIconExportUpdateProcess::ServerIconExportUpdateProcess(
23 const BPath
& localStorageDirectoryPath
)
25 fLocalStorageDirectoryPath
= localStorageDirectoryPath
;
29 ServerIconExportUpdateProcess::~ServerIconExportUpdateProcess()
35 ServerIconExportUpdateProcess::Run()
37 BPath
tarGzFilePath(tmpnam(NULL
));
38 status_t result
= B_OK
;
40 printf("will start fetching icons\n");
42 result
= Download(tarGzFilePath
);
44 if (result
!= APP_ERR_NOT_MODIFIED
) {
48 printf("delete any existing stored data\n");
49 StorageUtils::RemoveDirectoryContents(fLocalStorageDirectoryPath
);
51 BFile
*tarGzFile
= new BFile(tarGzFilePath
.Path(), O_RDONLY
);
54 BZlibDecompressionParameters
* zlibDecompressionParameters
55 = new BZlibDecompressionParameters();
57 result
= BZlibCompressionAlgorithm()
58 .CreateDecompressingInputStream(tarGzFile
,
59 zlibDecompressionParameters
, tarIn
);
62 result
= TarArchiveService::Unpack(*tarIn
,
63 fLocalStorageDirectoryPath
);
66 if (0 != remove(tarGzFilePath
.Path())) {
67 fprintf(stdout
, "unable to delete the temporary tgz path; "
68 "%s\n", tarGzFilePath
.Path());
76 printf("did complete fetching icons\n");
83 ServerIconExportUpdateProcess::GetStandardMetaDataPath(BPath
& path
) const
85 path
.SetTo(fLocalStorageDirectoryPath
.Path());
86 path
.Append("hicn/info.json");
91 ServerIconExportUpdateProcess::GetStandardMetaDataJsonPath(
92 BString
& jsonPath
) const
94 // the "$" here indicates that the data is at the top level.
100 ServerIconExportUpdateProcess::LoggingName() const
102 return "icon-export-update";
107 ServerIconExportUpdateProcess::Download(BPath
& tarGzFilePath
)
109 return DownloadToLocalFile(tarGzFilePath
,
110 ServerSettings::CreateFullUrl("/__pkgicon/all.tar.gz"), 0, 0);