Skip to content

Webcmdlets using -InFile parameter locks file #7669

Closed

Description

Currently when you upload a file via Invoke-Restmethod or Invoke-Webrequest and use the -InFile parameter, it puts a lock on the file, so no other process can read it. It does not set seem to set the FileShare.Read flag

(

SetRequestContent(request, new FileStream(InFile, FileMode.Open));
)

I am trying to parallelize to upload of single files to multiple locations.

Steps to reproduce

Run below command twice at the same time, either in multiple PS hosts, via jobs or runspaces.

Invoke-RestMethod -uri "https://artifactory/artifactory/my-tools/testfile.iso" -Method Put -InFile "C:\temp\testfile.iso" -Credential $creds -ContentType "multipart/form-data"

Expected behavior

I would not expect this to error since it is a read operation, I would suggest that the file is opened with FileShare.Read Flag, so you can have multiple processes access the file at the same time.


Actual behavior

When you run the commands simultaneously, you will get an The process cannot access the file 'C:\temp\testfile.iso' because it is being used by another process. error


Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-rc.1
PSEdition                      Core
GitCommitId                    6.1.0-rc.1
OS                             Microsoft Windows 10.0.17738
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Bug
    on Aug 31, 2018
  2. iSazonov commented on Aug 31, 2018

    @iSazonov
    Collaborator

    /cc Mark Kraus (@markekraus) Please look the Issue.

  3. Claustn commented on Aug 31, 2018

    @Claustn
    ContributorAuthor

    Had some time, so I built pwsh with these simple changes and now I can upload the file to multiple locations at the same time.

    SetRequestContent(request, new FileStream(InFile, FileMode.Open, FileAccess.Read, FileShare.Read));

  4. iSazonov commented on Aug 31, 2018

    @iSazonov
    Collaborator

    Claus T Nielsen (@Claustn) Feel free to offer PR.

  5. Claustn commented on Aug 31, 2018

    @Claustn
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions