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

Alternate data streams are removed by saving #6363

Closed
NotepadPlusUser opened this issue May 14, 2016 · 10 comments · Fixed by #42899
Closed

Alternate data streams are removed by saving #6363

NotepadPlusUser opened this issue May 14, 2016 · 10 comments · Fixed by #42899
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug file-io File I/O nodejs NodeJS support issues verified Verification succeeded
Milestone

Comments

@NotepadPlusUser
Copy link

  • VSCode Version:1.1.0
  • OS Windows Pro 10.0.10586.318 V1511

Steps to Reproduce:

  1. Open with VSCode a text file that has one or more alternate data stream files.
  2. Make some small change in the text.
  3. Save the file.
  4. The ADS files have been removed.

I'm sure that there is a setting that will prevent VSCode removing ADS files when saving — they are, after all, a Windows special. If not, could you please regard it as a bug and add such an option.

@bpasero
Copy link
Member

bpasero commented May 26, 2016

@NotepadPlusUser I would expect this issue to be there in standalone node.js already, if you could try out a fs.writeFile() to reproduce the issue you should report it to them.

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster labels May 26, 2016
@bpasero bpasero added this to the Backlog milestone May 26, 2016
@NotepadPlusUser
Copy link
Author

Thanks, bpasero, for looking at this issue and adding the 'bug' stamp to it. I have to apologise, however, that I don't understand what your reply means.

  1. Is your reply directed to me, or to the developers of VSCode?
  2. If the reply is to me, and is asking me to do something:
    (a) What does 'standalone node.js' mean? (I have a rather basic knowledgeof JScript.)
    (b) What is a 'fs.writefile()'?
    (c) Who is 'them?
    (d) What more information is needed? My 'steps to reproduce' seem a complete description of the issue and how to reproduce it.

@bpasero
Copy link
Member

bpasero commented May 27, 2016

@NotepadPlusUser node.js is the framework we use for writing to files so it would be interesting if this bug is a bug in node.js (https://nodejs.org/en/). By writing a small script like the following we could see if the issue is node.js related or not (using fs.writeFileSync from https://nodejs.org/docs/v5.10.0/api/fs.html#fs_fs_writefilesync_file_data_options):

var fs = require("fs");

fs. writeFileSync(filepath, "data");

Where filepath is the path to the file with data streams.

@NotepadPlusUser
Copy link
Author

Apologies bpasero, I'm completely out of my depth here.

I tried running the two lines as a bare .js file, but I get the error: Line 1, Char 1, Object expected. I tried running it another environment with the same result, By the way, in line 2, I had substituted filepath with the full path of the target file:
"D:\DataForVallaHome\Scripts\WSCLibrary\TestADSFiles.txt"

I tried instead to post you a TXT file that has two ADS TXT files attached, but of course the transfer to your servers removed them (I tested that by previewing and re-downloading).

Then I tried zipping the file first, but that also removed the ADS files..

So I'll have to leave it to the developers to sort out the origin of the problem and the fix. It's a serious matter for windows users, because you often want to put file metadata in an ADS file.

@bpasero
Copy link
Member

bpasero commented May 27, 2016

@NotepadPlusUser can you maybe explain how one gets a file with data streams on Windows? Then I can try to reproduce in node.js.

@NotepadPlusUser
Copy link
Author

[Next morning] Sure. Using good old DOS is the most direct way. The following 5 lines of DOS code will:

  1. Create a file called "MainFile.txt" in the current directory
  2. Create two attached ADS files, "FirstADSFile.txt" and "SecondADSFile.txt"
  3. List the current directory — the /r switch is what displays the otherwise hidden ADS files.

Echo "This is the main file" > MainFile.txt
Echo "Some content for the first ADS file" > MainFile.txt:FirstADSFile.txt
Echo "Some content for the second ADS file" > MainFile.txt:SecondADSFile.txt
Dir /r
Pause


So to reproduce the problem:

  1. Run these five lines from a DOS batch file or in a DOS window (preferably working within a directory with few files in it), and you will see the two attached ADS files listed on separate lines under MainFile.txt.
  2. Then open MainFile.txt with VSCode, make a small change to the text, and save it.
  3. Then run just the last two lines of the DOS code above, and the Dir /r command will now show that the two ADS files have been removed. I want to prevent that removal.

@bpasero bpasero removed the info-needed Issue requires more information from poster label May 28, 2016
@NotepadPlusUser
Copy link
Author

Thanks very much, bpasero, for handling this issue and confirming it. I'll keep a watch on the updates as they come out, and report back.

@bpasero
Copy link
Member

bpasero commented May 30, 2016

Thanks I am able to reproduce with just node.js so this is indeed an upstream issue it seems.

@bpasero bpasero added the upstream Issue identified as 'upstream' component related (exists outside of VS Code) label May 30, 2016
@bpasero bpasero added workbench file-explorer Explorer widget issues and removed workbench bug Issue identified by VS Code Team member as probable bug labels Apr 7, 2017
@bpasero bpasero added file-io File I/O nodejs NodeJS support issues and removed file-explorer Explorer widget issues labels Nov 12, 2017
@bpasero bpasero removed this from the Backlog milestone Nov 16, 2017
@f0zi
Copy link

f0zi commented Feb 3, 2018

All right, as @seishun mentioned:

To preserve data in alternate streams, consider using the 'r+' flag and ftruncate instead

@seishun
Copy link
Contributor

seishun commented Feb 3, 2018

VS Code already uses this logic for hidden files thanks to #31733. So it just needs to be applied to all existing files.

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug and removed upstream Issue identified as 'upstream' component related (exists outside of VS Code) labels Aug 20, 2018
@bpasero bpasero added this to the August 2018 milestone Aug 20, 2018
bpasero pushed a commit that referenced this issue Aug 20, 2018
* Use 'r+' with truncation when saving existing files on Windows

Opening a file with 'w' flag removes its alternate data streams. To
prevent this, extend the logic used for hidden files to all existing
files.

Fixes: #6363

* adopt truncate for saving as admin
@chrmarti chrmarti added the verified Verification succeeded label Aug 30, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug file-io File I/O nodejs NodeJS support issues verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants