0

I'm developing file sync client for Windows.

I use ReadDirectoryChangesW API for detecting file events (modifying, remove, create, etc.).

But ReadDirectoryChangesW reports NTFS ADS changes same as file modifications.

For example, when eml file is created, OS System add ADS on this file. (stream name is OECustomProperty). In this case, My Client can't distinguish between main stream and alternate data stream.

How to distinguish between modifying ADS and modifying the main stream?

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
lucidmaj7
  • 77
  • 1
  • 10
  • @YakovGalka for example `A.txt:stream` is Modifed, ReadDirectoryChangesW receive only `A.txt` file. But I want to receive `A.txt:stream` is modified. – lucidmaj7 Nov 29 '21 at 05:05
  • I guess windows doesn't provide any finer granularity. Your best bet is, as I said, when you receive a change on a file, to assume that all of the associated streams changed. – Yakov Galka Nov 29 '21 at 05:09
  • Is Any solution for this problem? I can give up using `ReadDirectoryChangesW`. – lucidmaj7 Nov 29 '21 at 05:22
  • Why is it a problem? It's not that you miss any notifications. – Yakov Galka Nov 29 '21 at 05:25
  • 1
    Problem is that my client is received modifying event although file is not modified(main stream). In this case, my client is trying to upload a file that is not modified(main stream) needlessly. – lucidmaj7 Nov 29 '21 at 05:34
  • Don't you check checksums before and after transferring the file? Before: so you don't transfer content that didn't change; After: to verify successful transfer. – Yakov Galka Nov 29 '21 at 05:39
  • I'm already know this solution. But I think checking checksum is too load(cpu useage..etc) to my client.. – lucidmaj7 Nov 29 '21 at 05:43
  • 2
    ReadDirectoryChangesW isn't 100% reliable anyway so I think you might be expecting too much – David Heffernan Nov 29 '21 at 07:36

1 Answers1

1

There are a number of alternative APIs you might consider. In particular, there's the NTFS Journal, with which you can review and sync based on things that happened since the last time you visited. You'd have to keep the last-read journal identifier...the USN...so you'd know where to start your processing.

It's kind of arcane, but it's super useful...especially for things like backup and sync programs. You can find an entry point to this world of wonder here.

Also, you'd be better off reading the entire $MSFT (the volume catalog) than iterating through folders. It's also a moderately arcane API, but orders of magnitude faster than iterating over folders. There's a description of how to read that in my answer to this question.

Clay
  • 4,999
  • 1
  • 28
  • 45