repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / server / ServerIconExportUpdateProcess.cpp
blobaf74cbf46b71ec7bab45c0b729b57f87d24e2803
1 /*
2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "ServerIconExportUpdateProcess.h"
8 #include <stdio.h>
9 #include <sys/stat.h>
10 #include <time.h>
12 #include <FileIO.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()
34 status_t
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) {
45 if (result != B_OK)
46 return result;
48 printf("delete any existing stored data\n");
49 StorageUtils::RemoveDirectoryContents(fLocalStorageDirectoryPath);
51 BFile *tarGzFile = new BFile(tarGzFilePath.Path(), O_RDONLY);
52 BDataIO* tarIn;
54 BZlibDecompressionParameters* zlibDecompressionParameters
55 = new BZlibDecompressionParameters();
57 result = BZlibCompressionAlgorithm()
58 .CreateDecompressingInputStream(tarGzFile,
59 zlibDecompressionParameters, tarIn);
61 if (result == B_OK) {
62 result = TarArchiveService::Unpack(*tarIn,
63 fLocalStorageDirectoryPath);
65 if (result == B_OK) {
66 if (0 != remove(tarGzFilePath.Path())) {
67 fprintf(stdout, "unable to delete the temporary tgz path; "
68 "%s\n", tarGzFilePath.Path());
73 delete tarGzFile;
76 printf("did complete fetching icons\n");
78 return result;
82 void
83 ServerIconExportUpdateProcess::GetStandardMetaDataPath(BPath& path) const
85 path.SetTo(fLocalStorageDirectoryPath.Path());
86 path.Append("hicn/info.json");
90 void
91 ServerIconExportUpdateProcess::GetStandardMetaDataJsonPath(
92 BString& jsonPath) const
94 // the "$" here indicates that the data is at the top level.
95 jsonPath.SetTo("$");
99 const char*
100 ServerIconExportUpdateProcess::LoggingName() const
102 return "icon-export-update";
106 status_t
107 ServerIconExportUpdateProcess::Download(BPath& tarGzFilePath)
109 return DownloadToLocalFile(tarGzFilePath,
110 ServerSettings::CreateFullUrl("/__pkgicon/all.tar.gz"), 0, 0);