~darling-team/darling-emu/darling-installer

« back to all changes in this revision

Viewing changes to src/pkg/Installer.cpp

  • Committer: GitHub
  • Author(s): Luboš Doležel
  • Date: 2017-01-13 23:26:27 UTC
  • mfrom: (19.1.2)
  • Revision ID: git-v1:692fcc21a036812027c68de91d0d623c4ecac2be
Merge pull request #4 from darlinghq/fix-wine

Fix Wine installation

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdexcept>
3
3
#include <memory>
4
4
#include <sys/stat.h>
 
5
#include <sys/types.h>
5
6
#include <fcntl.h>
6
7
#include <iostream>
7
8
#include <cstring>
138
139
        return path;
139
140
}
140
141
 
 
142
void Installer::mkParentDirs(const char *fileName, mode_t mode)
 
143
{
 
144
        // Create directories so that it's possible to create the specified file,
 
145
        // in a manner similiar to `mkdir -p`
 
146
 
 
147
        char *path = strdup(fileName);
 
148
 
 
149
        for (char *pos = path; pos != nullptr; pos = strchr(pos + 1, '/'))
 
150
        {
 
151
                if (pos == path)
 
152
                        continue;
 
153
 
 
154
                *pos = '\0';
 
155
 
 
156
                if (::mkdir(path, mode) != 0)
 
157
                {
 
158
                        if (errno != EEXIST)
 
159
                        {
 
160
                                std::stringstream ss;
 
161
                                ss << "Cannot mkdir " << path << ": " << strerror(errno);
 
162
                                throw std::runtime_error(ss.str());
 
163
                        }
 
164
                }
 
165
 
 
166
                *pos = '/';
 
167
        }
 
168
 
 
169
        free(path);
 
170
}
 
171
 
141
172
void Installer::extractPayload(const char* payloadFileName, std::string destinationDir)
142
173
{
143
174
        std::string path, name;
170
201
                path += name;
171
202
                
172
203
                // std::cout << path << std::endl;
173
 
                
 
204
 
 
205
                mkParentDirs(path.c_str(), st.st_mode & 0777);
 
206
 
174
207
                if (S_ISDIR(st.st_mode))
175
208
                {
176
209
                        if (::mkdir(path.c_str(), st.st_mode & 0777) != 0)
288
321
        char scriptsDir[] = "/tmp/installerXXXXXX";
289
322
        ReceiptsDb::InstalledPackageInfo installedPackageInfo;
290
323
        bool isUpgrade = false;
291
 
        
 
324
        Reader *bomReader;
 
325
 
292
326
        m_subdir = subdir;
293
327
        
294
328
        m_pkgInfo = loadPackageInfo();
359
393
        
360
394
        // Copy BOM file
361
395
        bomPath = ReceiptsDb::getInstalledPackageBOMPath(identifier.c_str());
362
 
        extractFile(std::shared_ptr<Reader>(m_xar->openFile(getSubdirFilePath("Bom"))), bomPath.c_str());
363
 
        
 
396
        bomReader = m_xar->openFile(getSubdirFilePath("Bom"));
 
397
        if (bomReader == nullptr)
 
398
                bomReader = m_xar->openFile(getSubdirFilePath("BOM"));
 
399
        if (bomReader == nullptr)
 
400
                throw std::runtime_error("Cannot find bom file");
 
401
        extractFile(std::shared_ptr<Reader>(bomReader), bomPath.c_str());
 
402
 
364
403
        return 0;
365
404
}
366
405