Пример #1
0
 def test_long_path_non_win(self):
     # Shouldn't have any effect on platforms other than Windows
     assert filesystem.long_path(r"\\?\UNC\test") == r"\\?\UNC\test"
     assert filesystem.long_path(r"\\?\F:\test") == r"\\?\F:\test"
     assert filesystem.long_path(r"\\test") == r"\\test"
     assert filesystem.long_path(r"F:\test") == r"F:\test"
     assert filesystem.long_path("/test/dir") == "/test/dir"
Пример #2
0
def prepare_extraction_path(nzo):
    """Based on the information that we have, generate
    the extraction path and create the directory.
    Separated so it can be called from DirectUnpacker
    """
    one_folder = False
    marker_file = None
    # Determine class directory
    catdir = config.get_categories(nzo.cat).dir()
    if catdir.endswith("*"):
        catdir = catdir.strip("*")
        one_folder = True
    complete_dir = real_path(cfg.complete_dir.get_path(), catdir)
    complete_dir = long_path(complete_dir)

    # TV/Movie/Date Renaming code part 1 - detect and construct paths
    if cfg.enable_meta():
        file_sorter = Sorter(nzo, nzo.cat)
    else:
        file_sorter = Sorter(None, nzo.cat)
    complete_dir = file_sorter.detect(nzo.final_name, complete_dir)
    if file_sorter.sort_file:
        one_folder = False

    complete_dir = sanitize_and_trim_path(complete_dir)

    if one_folder:
        workdir_complete = create_all_dirs(complete_dir, apply_umask=True)
    else:
        workdir_complete = get_unique_path(os.path.join(
            complete_dir, nzo.final_name),
                                           create_dir=True)
        marker_file = set_marker(workdir_complete)

    if not workdir_complete or not os.path.exists(workdir_complete):
        logging.error(
            T("Cannot create final folder %s") %
            os.path.join(complete_dir, nzo.final_name))
        raise IOError

    if cfg.folder_rename() and not one_folder:
        prefixed_path = prefix(workdir_complete, "_UNPACK_")
        tmp_workdir_complete = get_unique_path(prefix(workdir_complete,
                                                      "_UNPACK_"),
                                               create_dir=False)

        try:
            renamer(workdir_complete, tmp_workdir_complete)
        except:
            pass  # On failure, just use the original name

        # Is the unique path different? Then we also need to modify the final path
        if prefixed_path != tmp_workdir_complete:
            workdir_complete = workdir_complete + os.path.splitext(
                tmp_workdir_complete)[1]
    else:
        tmp_workdir_complete = workdir_complete

    return tmp_workdir_complete, workdir_complete, file_sorter, one_folder, marker_file
Пример #3
0
def check_incomplete_vs_complete():
    """Make sure download_dir and complete_dir are not identical
    or that download_dir is not a subfolder of complete_dir"""
    complete = cfg.complete_dir.get_path()
    if filesystem.same_file(cfg.download_dir.get_path(), complete):
        if filesystem.real_path("X", cfg.download_dir()) == filesystem.long_path(cfg.download_dir()):
            # Abs path, so set download_dir as an abs path inside the complete_dir
            cfg.download_dir.set(os.path.join(complete, "incomplete"))
        else:
            cfg.download_dir.set("incomplete")
        return False
    return True
Пример #4
0
 def test_nothing_to_lenghten_win(self):
     assert filesystem.long_path(r"\\?\UNC\test") == r"\\?\UNC\test"
     assert filesystem.long_path(r"\\?\F:\test") == r"\\?\F:\test"
Пример #5
0
 def test_long_path_win(self):
     assert filesystem.long_path(r"\\test") == r"\\?\UNC\test"
     assert filesystem.long_path(r"F:\test") == r"\\?\F:\test"
Пример #6
0
 def test_empty(self):
     assert filesystem.clip_path(None) is None
     assert filesystem.long_path(None) is None
Пример #7
0
    def create_unrar_instance(self):
        """ Start the unrar instance using the user's options """
        # Generate extraction path and save for post-proc
        if not self.unpack_dir_info:
            try:
                self.unpack_dir_info = prepare_extraction_path(self.nzo)
            except:
                # Prevent fatal crash if directory creation fails
                self.abort()
                return

        # Get the information
        extraction_path, _, _, one_folder, _ = self.unpack_dir_info

        # Set options
        if self.nzo.password:
            password_command = "-p%s" % self.nzo.password
        else:
            password_command = "-p-"

        if one_folder or cfg.flat_unpack():
            action = "e"
        else:
            action = "x"

        # The first NZF
        self.rarfile_nzf = self.have_next_volume()

        # Ignore if maybe this set is not there any more
        # This can happen due to race/timing issues when creating the sets
        if not self.rarfile_nzf:
            return

        # Generate command
        rarfile_path = os.path.join(self.nzo.downpath,
                                    self.rarfile_nzf.filename)
        if sabnzbd.WIN32:
            # For Unrar to support long-path, we need to cricumvent Python's list2cmdline
            # See: https://github.com/sabnzbd/sabnzbd/issues/1043
            command = [
                "%s" % sabnzbd.newsunpack.RAR_COMMAND,
                action,
                "-vp",
                "-idp",
                "-o+",
                "-ai",
                password_command,
                "%s" % clip_path(rarfile_path),
                "%s\\" % long_path(extraction_path),
            ]

        else:
            # Don't use "-ai" (not needed for non-Windows)
            command = [
                "%s" % sabnzbd.newsunpack.RAR_COMMAND,
                action,
                "-vp",
                "-idp",
                "-o+",
                password_command,
                "%s" % rarfile_path,
                "%s/" % extraction_path,
            ]

        if cfg.ignore_unrar_dates():
            command.insert(3, "-tsm-")

        # Let's start from the first one!
        self.cur_volume = 1

        # Need to disable buffer to have direct feedback
        self.active_instance = build_and_run_command(command,
                                                     flatten_command=True,
                                                     bufsize=0)

        # Add to runners
        ACTIVE_UNPACKERS.append(self)

        # Doing the first
        logging.info("DirectUnpacked volume %s for %s", self.cur_volume,
                     self.cur_setname)