Skip to content

Webcmdlets using -InFile parameter locks file #7669

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

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-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions