Exemplo n.º 1
0
static int loadSingleUrlImage(struct iurlinfo * ui, char * file,
                              char * dest, char * mntpoint, char * device,
                              int silentErrors) {
    int fd;
    int rc = 0;
    char * newFile = NULL;
    char filepath[1024];
    char *ehdrs = NULL;

    snprintf(filepath, sizeof(filepath), "%s", file);

    if (ui->protocol == URL_METHOD_HTTP) {
        ehdrs = (char *) malloc(24+strlen(VERSION));
        sprintf(ehdrs, "User-Agent: anaconda/%s\r\n", VERSION);
    }

    fd = urlinstStartTransfer(ui, filepath, ehdrs);

    if (fd == -2) {
        if (ehdrs) free (ehdrs);
        return 2;
    }

    if (fd < 0) {
        /* file not found */

        newFile = alloca(strlen(filepath) + 20);
        sprintf(newFile, "disc1/%s", filepath);

        fd = urlinstStartTransfer(ui, newFile, ehdrs);
        if (ehdrs) free (ehdrs);

        if (fd == -2) return 2;
        if (fd < 0) {
            if (!silentErrors)
                newtWinMessage(_("Error"), _("OK"),
                               _("Unable to retrieve %s://%s/%s/%s."),
                               (ui->protocol == URL_METHOD_FTP ? "ftp" :
                                "http"),
                               ui->address, ui->prefix, filepath);
            return 2;
        }
    }

    if (dest != NULL) {
        rc = copyFileAndLoopbackMount(fd, dest, device, mntpoint);
    }

    urlinstFinishTransfer(ui, fd);

    if (newFile) {
        newFile = malloc(strlen(ui->prefix) + 20);
        sprintf(newFile, "%s/disc1", ui->prefix);
        free(ui->prefix);
        ui->prefix = newFile;
    }

    return rc;
}
Exemplo n.º 2
0
static int loadSingleUrlImage(struct iurlinfo * ui, char *path,
                              char * dest, char * mntpoint, char * device,
                              int silentErrors) {
    int fd;
    int rc = 0;
    char *ehdrs = NULL;
    long long size;
    struct progressCBdata *data = NULL;

    if (ui->protocol == URL_METHOD_HTTP) {
        char *arch = getProductArch();
        char *name = getProductName();

        if (asprintf(&ehdrs, "User-Agent: anaconda/%s\r\n"
                             "X-Anaconda-Architecture: %s\r\n"
                             "X-Anaconda-System-Release: %s\r\n",
                     VERSION, arch, name) == -1) {
            logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
            abort();
        }
    }

    fd = urlinstStartTransfer(ui, path, ehdrs, &data, &size);

    if (fd == -2) {
        if (ehdrs) free (ehdrs);
        return 2;
    }
    else if (fd < 0) {
        if (!silentErrors) {
            newtWinMessage(_("Error"), _("OK"),
                           _("Unable to retrieve %s://%s%s."),
                           (ui->protocol == URL_METHOD_FTP ? "ftp" : "http"),
                           ui->address, path);
        }

        if (ehdrs) free (ehdrs);
        return 2;
    }

    if (dest != NULL) {
        rc = copyFileAndLoopbackMount(fd, dest, device, mntpoint,
                                      progressCallback, data, size);
    }

    urlinstFinishTransfer(ui, fd, &data);
    return rc;
}