Skip to content
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

scp locks the output file but it shouldn't #2246

Open
3 tasks done
RobbyCBennett opened this issue Jun 26, 2024 · 3 comments
Open
3 tasks done

scp locks the output file but it shouldn't #2246

RobbyCBennett opened this issue Jun 26, 2024 · 3 comments

Comments

@RobbyCBennett
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

  1. In CMD or PowerShell, download a big file into Windows with `scp
scp "hostname:big_input_file" big_output_file
  1. In another PowerShell terminal, while it's downloading, try to access it:
Get-Content big_output_file -TotalCount 2KB
  1. See the following error:
Get-Content: The process cannot access the file 'C:\Users\Robby\Desktop\big_output_file' because it is being used by another process.

Expected behavior

I'm trying to download a big file with `scp` and read it during the download in another program. This works with `scp` in WSL, but not in Windows.

Actual behavior

In Windows, I can't read from the file because it gets locked by `scp`.

Error details

Exception             :
    Type       : System.IO.IOException
    TargetSite :
        Name          : CreateFile
        DeclaringType : [Microsoft.Win32.SafeHandles.SafeFileHandle]
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : The process cannot access the file 'C:\Users\Robby\Desktop\big_output_file' because it is being
used by another process.
    Source     : System.Private.CoreLib
    HResult    : -2147024864
    StackTrace :
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access,
FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare
share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share,
FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access,
FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.CreateStreams(String filePath, String streamName,
FileMode fileMode, FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter..ctor(String path, String streamName, FileMode mode,
FileAccess access, FileShare share, Encoding encoding, Boolean usingByteEncoding, Boolean waitForChanges,
CmdletProvider provider, Boolean isRawStream)
   at Microsoft.PowerShell.Commands.FileSystemProvider.GetContentReader(String path)
TargetObject          : C:\Users\Robby\Desktop\big_output_file.mkv
CategoryInfo          : ReadError: (C:\Users\Robby\Desktop\big_output_file:String) [Get-Content], IOException
FullyQualifiedErrorId : GetContentReaderIOError,Microsoft.PowerShell.Commands.GetContentCommand
InvocationInfo        :
    MyCommand        : Get-Content
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 15
    Line             : Get-Content $env:file -TotalCount 2KB
    Statement        : Get-Content $env:file -TotalCount 2KB
    PositionMessage  : At line:1 char:1
                       + Get-Content $env:file -TotalCount 2KB
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Get-Content
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2

Visuals

No response

@maertendMSFT
Copy link
Collaborator

We don't believe this is a scp issue, we believe this is consistent behavior across Windows.

If you copy the same large file from one location to another on your computer, can you open and read the file in the new location while it is being copied?

@maertendMSFT maertendMSFT added the Waiting on Author Need more information to diagnose label Jul 1, 2024
@RobbyCBennett
Copy link
Author

You are correct that the same behavior exists across Windows. I have the same issue with the copy command.

Just because it's consistent, it does not make it correct. There should be a way to disable the locking. If the desire is to make this tool more like Linux, then locking should be an opt-in feature. Regardless of whether it's opt-in or opt-out, there should be a way to disable locking.

@NoMoreFood
Copy link

This usually comes down to the CreateFile API and whether the FILE_SHARE_READ and FILE_SHARE_WRITE flags were passed in. I don't recall if the fork is using CreateFile directly or using the POSIX-esque calls.

@tgauth tgauth added Area-SCP Issue-Upstream Parity and removed Waiting on Author Need more information to diagnose labels Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants