Exemplo n.º 1
0
    def _extract(self, pyfile, archive, password):
        name = os.path.basename(archive.filename)

        pyfile.setStatus("processing")

        encrypted = False
        try:
            self.logDebug("Password: %s" % (password or "None provided"))
            passwords = uniqify([password] +
                                self.getPasswords(False)) if self.getConfig(
                                    'usepasswordfile') else [password]
            for pw in passwords:
                try:
                    if self.getConfig('test') or self.repair:
                        pyfile.setCustomStatus(_("archive testing"))
                        if pw:
                            self.logDebug("Testing with password: %s" % pw)
                        pyfile.setProgress(0)
                        archive.verify(pw)
                        pyfile.setProgress(100)
                    else:
                        archive.check(pw)

                    self.addPassword(pw)
                    break

                except PasswordError:
                    if not encrypted:
                        self.logInfo(name, _("Password protected"))
                        encrypted = True

                except CRCError, e:
                    self.logDebug(name, e)
                    self.logInfo(name, _("CRC Error"))

                    if self.repair:
                        self.logWarning(name, _("Repairing..."))

                        pyfile.setCustomStatus(_("archive repairing"))
                        pyfile.setProgress(0)
                        repaired = archive.repair()
                        pyfile.setProgress(100)

                        if not repaired and not self.getConfig('keepbroken'):
                            raise CRCError("Archive damaged")

                        self.addPassword(pw)
                        break

                    raise CRCError("Archive damaged")

                except ArchiveError, e:
                    raise ArchiveError(e)
Exemplo n.º 2
0
    def extract(self, password=None):
        command = "x" if self.fullpath else "e"

        p = self.call_cmd(command,
                          fs_encode(self.filename),
                          self.out,
                          password=password)

        renice(p.pid, self.renice)

        # communicate and retrieve stderr
        self._progress(p)
        err = p.stderr.read().strip()

        if err:
            if self.re_wrongpwd.search(err):
                raise PasswordError

            elif self.re_wrongcrc.search(err):
                raise CRCError(err)

            else:  #: raise error if anything is on stderr
                raise ArchiveError(err)

        if p.returncode:
            raise ArchiveError(_("Process return code: %d") % p.returncode)

        self.files = self.list(password)
Exemplo n.º 3
0
    def verify(self):
        with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
            badfile = z.testzip()

            if badfile:
                raise CRCError(badfile)
            else:
                raise PasswordError
Exemplo n.º 4
0
    def verify(self, password):
        p = self.call_cmd("t", "-v", fs_encode(self.filename), password=password)
        self._progress(p)
        err = p.stderr.read().strip()

        if self.re_wrongpwd.search(err):
            raise PasswordError

        if self.re_wrongcrc.search(err):
            raise CRCError(err)
Exemplo n.º 5
0
    def check(self, password):
        p = self.call_cmd("l", "-v", fs_encode(self.filename), password=password)
        out, err = p.communicate()

        if self.re_wrongpwd.search(err):
            raise PasswordError

        if self.re_wrongcrc.search(err):
            raise CRCError(err)

        # output only used to check if passworded files are present
        for attr in self.re_filelist.findall(out):
            if attr[0].startswith("*"):
                raise PasswordError
Exemplo n.º 6
0
    def extract(self, password=None):
        try:
            with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
                z.setpassword(password)

                badfile = z.testzip()

                if badfile:
                    raise CRCError(badfile)
                else:
                    z.extractall(self.out)

        except (zipfile.BadZipfile, zipfile.LargeZipFile), e:
            raise ArchiveError(e)