Skip to content

Fix ArchiveFilesV2 task to properly handle adding single files to existing archives #21036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 20, 2025

Issue

When using the ArchiveFilesV2 task with rootFolderOrFile pointing to a single file and includeRootFolder: false, adding to an existing archive (replaceExistingArchive: false) fails with a "Nothing to do" error.

Root Cause

The findFiles() function was not correctly handling the case when includeRootFolder is false and rootFolderOrFile points to a single file. The function was using tl.ls(), which is designed to list directory contents but doesn't handle file paths properly.

Fix

Added a check in the findFiles() function to determine if rootFolderOrFile is a file when includeRootFolder is false. If it is a file, the function now returns the basename of the file directly, matching the behavior when includeRootFolder is true.

function findFiles(): string[] {
    if (includeRootFolder) {
        // Existing code...
    } else {
        // Check if rootFolderOrFile is a file
        if (fs.existsSync(rootFolderOrFile) && fs.statSync(rootFolderOrFile).isFile()) {
            return [path.basename(rootFolderOrFile)];
        } else {
            // Existing code for directory case...
        }
    }
}

Testing

Added a new test case Successfully adds a single file to an existing archive that verifies the task can properly add a single file to an existing archive.

Fixes #21033.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
    • Triggering command: /usr/bin/fwupdmgr refresh (dns block)
  • pkgs.dev.azure.com
    • Triggering command: npm install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] [BUG]: Newest ArchiveFilesV2 is failing on adding single file to existing archive - rollback to previous version helped Fix ArchiveFilesV2 task to properly handle adding single files to existing archives May 20, 2025
@Copilot Copilot AI requested a review from ivanduplenskikh May 20, 2025 12:36
for (var i = 0; i < fullPaths.length; i++) {
baseNames[i] = path.basename(fullPaths[i]);
// Check if rootFolderOrFile is a file
if (fs.existsSync(rootFolderOrFile) && fs.statSync(rootFolderOrFile).isFile()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, could you please add an additional check there with the feature flag DistributedTasks.Task.ArchiveOneFileWithRootFolderInput to ensure it is executed only when this flag is enabled by using tl.getPipelineFeature?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the feature flag check as requested. The single file handling in the findFiles() function now only works when the DistributedTasks.Task.ArchiveOneFileWithRootFolderInput feature flag is enabled. When the flag is disabled, it falls back to the original behavior. Changes are in commit 481a343.

@Driver-glitch
Copy link

Good afternoon, Is the fix for this going to happen soon? We have dependencies for this due to the build pipelines failing.

@dsherret
Copy link

@Driver-glitch just do this:

- - task: ArchiveFiles@2
+ - task: [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Newest ArchiveFilesV2 is failing on adding single file to existing archive - rollback to previous version helped
4 participants