@Override
    public void visit(final File f, final String _relativePath) throws IOException {
        int mode = IOUtils.mode(f);

        // On Windows, the elements of relativePath are separated by
        // back-slashes (\), but Zip files need to have their path elements separated
        // by forward-slashes (/)
        String relativePath = _relativePath.replace('\\', '/');

        BasicFileAttributes basicFileAttributes = Files.readAttributes(Util.fileToPath(f), BasicFileAttributes.class);
        if (basicFileAttributes.isDirectory()) {
            ZipEntry dirZipEntry = new ZipEntry(this.prefix + relativePath + '/');
            // Setting this bit explicitly is needed by some unzipping applications (see JENKINS-3294).
            dirZipEntry.setExternalAttributes(BITMASK_IS_DIRECTORY);
            if (mode != -1)   dirZipEntry.setUnixMode(mode);
            dirZipEntry.setTime(basicFileAttributes.lastModifiedTime().toMillis());
            zip.putNextEntry(dirZipEntry);
            zip.closeEntry();
        } else {
            ZipEntry fileZipEntry = new ZipEntry(this.prefix + relativePath);
            if (mode != -1)   fileZipEntry.setUnixMode(mode);
            fileZipEntry.setTime(basicFileAttributes.lastModifiedTime().toMillis());
            fileZipEntry.setSize(basicFileAttributes.size());
            zip.putNextEntry(fileZipEntry);
            try (InputStream in = FilePath.openInputStream(f, openOptions)) {
                int len;
                while ((len = in.read(buf)) >= 0)
                    zip.write(buf, 0, len);
            } catch (InvalidPathException e) {
                throw new IOException(e);
            }
            zip.closeEntry();
        }
        entriesWritten++;
    }
@Issue("JENKINS-9942")
    @Test
    public void backwardsSlashesOnWindows() throws IOException {
        // create foo/bar/baz/Test.txt
        Path baz = tmp.newFolder().toPath().resolve("foo").resolve("bar").resolve("baz");
        Files.createDirectories(baz);
        Path tmpFile = baz.resolve("Test.txt");
        Files.createFile(tmpFile);

        // a file to store the zip archive in
        Path zipFile = Files.createTempFile(tmp.getRoot().toPath(), "test", ".zip");

        // create zip from tmpDir
        try (ZipArchiver archiver = new ZipArchiver(Files.newOutputStream(zipFile))) {
            archiver.visit(tmpFile.toFile(), "foo\\bar\\baz\\Test.txt");
        }

        // examine zip contents and assert that none of the entry names (paths) have
        // back-slashes ("\")
        try (ZipFile zipFileVerify = new ZipFile(zipFile.toFile())) {
            assertEquals(1, zipFileVerify.size());
            ZipEntry zipEntry = zipFileVerify.entries().nextElement();
            assertEquals("foo/bar/baz/Test.txt", zipEntry.getName());
        }
    }