aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader/phar_downloader.rs
blob: 5316fc1e2dafc44f0244e5b70ed44ea0a356941c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! ref: composer/src/Composer/Downloader/PharDownloader.php

use crate::downloader::archive_downloader::ArchiveDownloader;
use crate::downloader::file_downloader::FileDownloader;
use crate::package::package_interface::PackageInterface;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::react::promise::promise_interface::PromiseInterface;
use shirabe_php_shim::Phar;

#[derive(Debug)]
pub struct PharDownloader {
    inner: FileDownloader,
    cleanup_executed: IndexMap<String, bool>,
}

impl PharDownloader {
    pub(crate) fn extract(
        &self,
        package: &dyn PackageInterface,
        file: &str,
        path: &str,
    ) -> Result<Box<dyn PromiseInterface>> {
        // Can throw an UnexpectedValueException
        let archive = Phar::new(file.to_string());
        archive.extract_to(path, None, true);
        // TODO: handle openssl signed phars
        // https://github.com/composer/composer/pull/33#issuecomment-2250768
        // https://github.com/koto/phar-util
        // http://blog.kotowicz.net/2010/08/hardening-php-how-to-securely-include.html

        Ok(shirabe_external_packages::react::promise::resolve(None))
    }
}