locked
FileIO AppendTextAsync sets hidden attribute on file

    Question

  • For an Windows Store App, I created a JavaScript logging module which writes log messages to a file with Windows.Storage.FileIO.appendTextAsync. Unfortunately, this method appears to have some strange behavior: sometimes, the hidden attribute is set on the file. When I start the app another time, the log file is not found (because of its hidden attribute set) and the app crashes because it can not create a new file with the same name (because it already exists).

    I also observed that the file is sometimes copied to a temp file with a hidden attribute when writing to the file, and when that temporary file has disappeared/deleted, the original file has its hidden attribute set and it will never loose it.

    Looking around for a solution I found that it is not possible to set or unset the hidden attribute with the FileIO API.

    So I have two questions:

    1) is it possible to get rid of that hidden attribute on the log file?

    2) is it a bug that a file, when written to with AppendTextAsync, gets the hidden attribute set?

    Thanks in advance.

    Friday, January 3, 2014 7:32 AM

Answers

  • You do not have control over the hidden flag that is set on the file because the File IO that you are performing is not being done by your process, but instead it is a brokered write to the file system. There is a file system broker process that performs the actual interaction with the file system.

    If you have a repro of the weird behavior you are experiencing then please share it via SkyDrive to understand where exactly the problem lies.

    Btw, do you have any type of Antivirus software installed that is performing any "real time" monitoring of the File System? You could probably try switching this file system monitoring functionality and check if it is contributing to your overall issue.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog


    Saturday, January 4, 2014 1:16 AM
    Moderator

All replies

  • You do not have control over the hidden flag that is set on the file because the File IO that you are performing is not being done by your process, but instead it is a brokered write to the file system. There is a file system broker process that performs the actual interaction with the file system.

    If you have a repro of the weird behavior you are experiencing then please share it via SkyDrive to understand where exactly the problem lies.

    Btw, do you have any type of Antivirus software installed that is performing any "real time" monitoring of the File System? You could probably try switching this file system monitoring functionality and check if it is contributing to your overall issue.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog


    Saturday, January 4, 2014 1:16 AM
    Moderator
  • Sorry for coming back lately, I've been busy on other things.

    I've made a bare bone application which reproduces the problem. The solution can be found here:

    StoreApp.zip

    The app writes a logmessage to a queue, and the messages in the queue will be written when the FileIO.AppendAsync is not busy. (If this is done without a queue, the AppendAsync will crash.)

    Run the app for a few seconds, watch the logfile in Windows Explorer (or another file manager tool) and see the hidden attribute appear on the file.

    I just reproduced the problem, I will go and investigate the problem myself. Meanwhile, I appreciate your help with this.

    Thursday, January 16, 2014 2:47 PM
  • Thanks for sharing the repro. Using your code, I can see the LoggingTest.log file get created, but it always have the attributes of "A". I have run the project multiple times now, but each time the file ends up with the "A" attribute and does not have "HA".

    When you perform the writes to the file system, RuntimeBroker.exe performs the actual interaction with the file system by creating temporary files - which have the "HA" attribute and then that temporary file will replace the actual file.

    We have only seen this issue with "Realtime file system monitoring software" such as an Anti-virus software running on systems which can contribute to these type of issues. Do you have any such software running on your system?

    I cannot reproduce the issue you have reported. The file always ends up with the "A" attribute, never with the "HA" attribute.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Thursday, January 16, 2014 11:24 PM
    Moderator
  • You were right, it was the anti-virus software, McAfee in our case. Due to group policy settings, I can not turn it off, or exclude the relevant directories. I got a hand on a tablet with Windows 8 and without anti-virus, and with the remote debugger, the bug did not appear.

    Thank you for pointing me in the right direction.

    Friday, January 17, 2014 11:39 AM