Skip to content

USER_WORKING_DIR is concatenating "C:/" to the path in Windows #1205

@stevensgarcia

Description

@stevensgarcia

Hi,

I'm using a main Taskfile which includes a vagrant_taskfile.yml.

# Windows
# C:\Users\Usuario\taskfiles\Taskfile.yml
version: '3'

includes:
  vagrant: 
    taskfile: ./vagrant_taskfile.yml

I've experienced this concatenating issue with {{.USER_WORKKING_DIR}} before in Linux and solved it using this config:

# Linux
# /home/user/taskfiles/vagrant_taskfile.yml
ssh:
    dir: "../../../{{.USER_WORKING_DIR}}"
    cmds:
      - vagrant ssh

This works perfectly OK in Linux. However in Windows 10 Pro Powershell it fails:

# Windows - PowerShell
# Execution context: C:\Users\Usuario\Documents\Vagrant_Projects\demo

task: [main:vagrant:ssh] vagrant ssh
task: Failed to run task "main:vagrant:ssh": could not stat: CreateFile C:\C:\Users\Usuario\Documents\Vagrant_Projects\demo: The filename, directory name, or volume label syntax is incorrect.

⚠️ Please note the concatenated C:\ at the beginning of the execution path. This is the problem. ⚠️

No matter how I play with the hierarchy path ../../, those parent dirs will be removed, but that C:\ will remain attached to the path, so the command wont work. Not to mention that if I only use {{.USER_WORKING_DIR}} it will concatenate the main and current context paths together ending with the old problem.

# Windows
# C:\Users\Usuario\taskfiles\vagrant_taskfile.yml
ssh:
    dir: "../../../{{.USER_WORKING_DIR}}"
    cmds:
      - vagrant ssh
# Windows - PowerShell
# Execution context: C:\Users\Usuario\Documents\Vagrant_Projects\demo

task: [main:vagrant:ssh] vagrant ssh
task: Failed to run task "main:vagrant:ssh": could not stat: CreateFile C:\Users\Usuario\taskfiles\C:\Users\Usuario\Documents\Vagrant_Projects\demo: The filename, directory name, or volume label syntax is incorrect.

Here you can see both paths got concatenated. As mentioned in the beginning, this can be solved usign dir: "../../../{{.USER_WORKING_DIR}}" in Linux.

Any suggestions to fix this in Windows?

PS: All other commands that don't require .USER_WORKING_DIR work like a charm in windows so far.

Thank you very much.

  • Task version: v3.19.1 (h1:2KMJk6mDBacSPuFxPFvlvvHJwGZtU/hN2ENZpaFqR5s=)
  • Operating system: Windows 10 Pro, Powershell

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: variablesChanges related to variables.os: windowsIssues that affect users on Windows.

    Type

    No fields configured for bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions