Open archive

@param string $archive
@param bool $create
@return bool
513343
private function open($archive, $create = false)
		{
			if (true === $this->_enabled) {
				$archive = repl('/', DS, $archive);

				if ($create) {
					$this->_archive	= $this->_zip->open($archive, \ZipArchive::CREATE);
				} else if (File::exists($archive)) {
					$this->_archive	= $this->_zip->open($archive);
				}

				if ($this->_archive === true) {
					$this->contents();

					return true;
				} else {
					$this->error();

					return false;
				}
			}

			return false;
		}
307839
function checkAndOrCreateDir($dir, $create = false, $perm = '0777')
    {
        if(is_dir($dir) && is_writable($dir)) return true;
        elseif($create === false) return false;

        @mkdir($dir, $perm, true);
        @chmod($dir, $perm);

        if(is_writable($dir)) return true;
        return false;
    }
86147
public static function createZip($destination, $files = [], $blobs = [], $overwrite = true)
    {
        if (!class_exists('ZipArchive')) {
            throw new \Exception('cannot_create_zip_archive');
        }
        //if the zip file already exists and overwrite is false, return false
        if (file_exists($destination) && !$overwrite) {
            return false;
        }
        /* //vars
          $valid_files = array( );
          //if files were passed in...
          if (is_array( $files )) {
          //cycle through each file
          foreach ($files as $file) {
          //make sure the file exists
          if (file_exists( $file )) {
          $valid_files[ ] = $file;
          }
          }
          } */
        //if we have good files...
        // if (count( $valid_files )) {
        //create the archive
        $zip = new ZipArchive();

        if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
            return false;
        }
        //Add the files
        foreach ($files as $file) {
            $filename = $blob['filename'];
            $path = $blob['path'];

            if (!file_exists($path)) {
                throw new \Exception('file_NotFoundException');
            }
            $zip->addFile($filename, $path);
        }
        //Add the $blobs
        foreach ($blobs as $blob) {
            $filename = $blob['filename'];
            $contents = $blob['contents'];
            $zip->addFromString($filename, $contents);
        }

        //debug
        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
        //close the zip -- done!
        $zip->close();
        //check to make sure the file exists
        return file_exists($destination);
        // } else {
        //     return FALSE;
        //}
    }
1256909
public function append($content, $create = false)
    {

        if ($this->writeable !== true || empty($content)) return false;

        if (strpos($this->_option, 'a') === false) {
            // close open filepoint
            if (!empty($this->fp)) fclose($this->fp);
            // opens fp for writing with file lock
            $this->open_fp((is_bool($create) && $create === true ? 'a+' : 'a'));
        }

        if ($this->file_lock !== true && !$this->lock(LOCK_EX)) return false;

        // writes to file
        fputs($this->fp, $content, strlen($content));
        // releases lock
        $this->lock(LOCK_UN);

        return true;
    }
205751
public function open($savePath, $sessionName): bool
    {
        $this->savePath = $savePath;
        Directory::create($this->savePath);
        return true;
    }
852485
def _create(opener,
            format_code,
            files,
            filter_code=None,
            block_size=16384):
    """"""

    a = _archive_write_new()
    _set_write_context(a, format_code, filter_code)

    _LOGGER.debug("Opening archive (create).")
    opener(a)

# Use the standard uid/gid lookup mechanisms.
# This was set on an instance of *disk* that wasn't used. Do we still need it?
#_archive_read_disk_set_standard_lookup(disk)

    # We used to yield this, but that necessitated users always flattening the
    # response. This means we don't have to, but we still have to return an
    # enumerable in order to maintain compatibility.
    added = []

    for filepath in files:
        filepath = filepath.encode('utf-8')

        disk = libarchive.calls.archive_read.c_archive_read_disk_new()
        libarchive.calls.archive_read.c_archive_read_disk_open(
            disk,
            filepath)

        while 1:
            entry = libarchive.calls.archive_entry.c_archive_entry_new()
            r = libarchive.calls.archive_read.c_archive_read_next_header2(
                    disk,
                    entry)

            if r == libarchive.constants.archive.ARCHIVE_EOF:
                break
            elif r != libarchive.constants.archive.ARCHIVE_OK:
                message = c_archive_error_string(disk)
                raise libarchive.exception.ArchiveError(
                        "Could not build header from physical source file "
                        "during create: (%d) [%s]" %
                        (r, message))

            ae = libarchive.adapters.archive_entry.ArchiveEntry(
                        disk,
                        entry)

            # print("WRITING: [{}] {}".format(ae, ae.filetype))

            # Strip leading slash so it stores as a relative path.
            if os.path.isabs(ae.pathname) is True:
                ae.pathname = ae.pathname[1:]

            added.append(ae)

            libarchive.calls.archive_read.c_archive_read_disk_descend(disk)

            # NOTE: There's a `archive_entry_set_size()` on the underlying
            # entry type, but it doesn't appear to be necessary. The sizes
            # report perfectly fine with the [probably automatic] counting that
            # occurs just with `_archive_write_data()`.

            r = _archive_write_header(a, entry)

            if ae.filetype.IFLNK is True and os.path.islink(ae.sourcepath) is True:
                target_path = os.readlink(ae.sourcepath)
                ae.symlink_targetpath = target_path
            else:
                with open(ae.sourcepath, 'rb') as f:
                    while 1:
                        data = f.read(block_size)
                        if not data:
                            break

                        _archive_write_data(a, data)

            libarchive.calls.archive_entry.c_archive_entry_free(entry)

        libarchive.calls.archive_read.c_archive_read_close(disk)
        libarchive.calls.archive_read.c_archive_read_free(disk)

    _LOGGER.debug("Closing archive (create).")

    _archive_write_close(a)
    _archive_write_free(a)

    return added
1354811
public function create()
    {
        $folder = $this->getBackupFolder();

        $files = $this->backupFiles($folder);
        $db = $this->backupDatabase($folder);

        $resultFilename = $this->getBackupFilename();
        $archiveFile = dirname($folder) . DIRECTORY_SEPARATOR . $resultFilename . '.tar';

        // Create new archive
        $archive = new \PharData($archiveFile);

        // add folder
        $archive->buildFromDirectory($folder);

        // Remove temp directory
        FileHelper::removeDirectory($folder);

        return $archiveFile;
    }
73494
public function open($savePath, $sessionName)
    {
        if (empty($this->table) || empty($this->database) || empty($this->siteName)) {
            return false;
        }

        return true;
    }
299270
public function create($file = '')
    {
        $this->file   = $file;
        $this->memory = '';
        $this->fh     = 0;

        if ($this->file) {
            $this->fh = @fopen($this->file, 'wb');

            if (!$this->fh) {
                throw new ArchiveIOException('Could not open file for writing: '.$this->file);
            }
        }
        $this->writeaccess = true;
        $this->closed      = false;
        $this->ctrl_dir    = array();
    }
324697
public function install($archive, $name)
    {
        $exploadName = explode('.', $name);
        $name = $exploadName[0];
        $storageData = route()->storage_data;
        $file = $storageData.$archive;
        $files = new Files();
        $files->mkdir($storageData.'tmp/');
        $files->mkdir($storageData.'tmp/'.$name);
        (new Zip())->extract($file, $storageData.'tmp/'.$name.'/', true);
        if (file_exists($storageData.'tmp/'.$name.'/component.json')) {
            $file = new FileHandling();
            $c = $file->open($storageData.'/tmp/'.$name.'/component.json', 'readOnly')->read();
            $file->close();
            $config = json_decode($c, true);
            if ($this->isSupported($config['requires']['version'], $config['requires']['comparator']) === true) {
                if (!file_exists(route()->com.$name)) {
                    $files->moveDir($storageData.'tmp/', route()->com, $name);

                    return true;
                }
            }
        }

        return false;
    }
106754
protected function archive()
    {
        if( $archiveDatabaseList = $this->getArchiveDatabaseList() )
        {
            foreach( $archiveDatabaseList as $database )
            {
                if( ! empty($tables = $this->getArchiveDatabaseTableList($database)) )
                {
                    $dbForge = $this->getDBForgeDifferentConnectionByDatabaseName($database);
    
                    foreach( $tables as $table )
                    {
                        $dbForge->dropTable($this->getTableNameWithoutExtension($table));
                    }
                }
    
                $tool = $this->getDBToolDifferentConnectionByDatabaseName($database);
    
                if( empty($tool->listTables()) )
                {
                    $this->forge->dropDatabase($database);
                }
            }

            return true;
        }
        
        return false;
    }
763848
protected static function createArchiveForPhar(array $files, $archiveFileName)
    {
        if (preg_match('~^(.+)\.(tar\.(gz|bz2))$~i', $archiveFileName, $match)) {
            $ext = $match[2];
            $basename = $match[1];
        } else {
            $ext = pathinfo($archiveFileName, PATHINFO_EXTENSION);
            $basename = dirname($archiveFileName).'/'.basename($archiveFileName, '.'.$ext);
        }
        $tar = new PharData($basename.'.tar', 0, null, Phar::TAR);

        try {
            foreach ($files as $localName => $filename) {
                if (is_null($filename)) {
                    if (!in_array($localName, ['/', ''], true)) {
                        if ($tar->addEmptyDir($localName) === false) {
                            return false;
                        }
                    }
                } else {
                    if ($tar->addFile($filename, $localName) === false) {
                        return false;
                    }
                }
            }
        } catch (Exception $e) {
            return false;
        }

        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $tar->compress(Phar::GZ, $ext);
                break;
            case 'bz2':
            case 'tbz2':
                $tar->compress(Phar::BZ2, $ext);
                break;
        }
        $tar = null;

        return count($files);
    }
1293212
public static function createArchive(array $files, $archiveFileName){
        if (count($files) > 1) return false;
        $filename = array_shift($files);
        if (is_null($filename)) return false; // invalid list
        if (file_put_contents($archiveFileName,
                static::compressData(file_get_contents($filename))) !== false)
            return 1;
    }
261086
public static function createArchive(array $files, $archiveFileName) {
        $seven_zip = new Archive7z($archiveFileName);
        try {
            foreach ($files as $localName => $filename) {
                if ($filename !== null) {
                    $seven_zip->addEntry($filename, true);
                    $seven_zip->renameEntry($filename, $localName);
                }
            }
            unset($seven_zip);
        } catch (Exception $e) {
            throw new Exception('Could not create archive: '.$e->getMessage(), $e->getCode(), $e);
        }
        return count($files);
    }
565916
private function getMeta($create = false)
    {
        $locale = $this->locale;
        $metaCollection = $this->getFileVersion()->getMeta();

        // get meta only with this locale
        $metaCollectionFiltered = $metaCollection->filter(function($meta) use ($locale) {
            /** @var FileVersionMeta $meta */
            if ($meta->getLocale() == $locale) {
                return true;
            }

            return false;
        });

        // check if meta was found
        if ($metaCollectionFiltered->isEmpty()) {
            if ($create) {
                // create when not found
                $meta = new FileVersionMeta();
                $meta->setLocale($this->locale);
                $meta->setFileVersion($this->getFileVersion());
                $this->getFileVersion()->addMeta($meta);

                return $meta;
            }

            // return first when create false
            return $this->getFileVersion()->getDefaultMeta();
        }

        // return exists
        return $metaCollectionFiltered->first();
    }
235096
protected function addArchive(Builder $builder): void
    {
        $builder->macro('archive', function (Builder $builder) {
            return $builder->update(['is_archived' => 1]);
        });
    }
607041
public function moveToFolder($mailbox = 'INBOX', $expunge = false, $create_folder = true) {

        if($create_folder) $this->client->createFolder($mailbox, true);

        $target_folder = $this->client->getFolder($mailbox);
        $target_status = $target_folder->getStatus(IMAP::SA_ALL);

        $this->client->openFolder($this->folder_path);
        $status = imap_mail_move($this->client->getConnection(), $this->uid, $mailbox, IMAP::CP_UID);

        if($status === true){
            if($expunge) $this->client->expunge();
            $this->client->openFolder($target_folder->path);

            return $target_folder->getMessage($target_status->uidnext, $this->msglist, $this->fetch_options, $this->fetch_body, $this->fetch_attachment, $this->fetch_flags);
        }

        return null;
    }