Help: OneDrive Directory Synchronization Status?
Today’s version of screaming a prayer into the abyss is a plea to the Microsoft OneDrive developers, though it applies equally to other cloud storage providers who offer a “sync app” for local installation on Windows endpoints, for example Box, ShareFile, et al:
There is frequently (trust me on this!) a need in enterprise environments to ensure that a certain prepopulated folder tree exists in every user’s “sync folder”, maybe because an app is configured to store its data there persistently, maybe to redirect some user folder to cloud storage, etc. A “naïve” script to achieve this at logon would typically wait for the sync folder to appear in the user profile, then would check whether the desired folder tree already exists, and finally would create it if it isn’t present. But this of course ignores the reality that the local sync folder’s directory contents may not yet be fully up-to-date by the time the script performs its check, so the folder tree may wind up being prematurely recreated, eventually leading to various types of duplicate objects being created as the directory synchronization proceeds:
For example, if the simple structure “AppABC\Config\config.dat” is unnecessarily recreated too early after logon, the user may also wind up with something like “AppABC (2)\Config\config.dat“, or “AppABC\Config (2)\config.dat“, or even the duplicate renamed file “AppABC\Config\config-computername.dat“, depending on the relative timing of the script actions and the sync app’s directory refresh. And of course, over time further similar duplicates with different names will continue being created in the course of subsequent logons.
You might argue that a more sophisticated script is needed that waits some fixed amount of time before deciding whether the folder tree needs to be created, but whatever delay you choose based on current observation of the directory sync time will undoubtedly someday (or for some users) turn out to be insufficient due to network conditions, to the size of the user’s directory tree, or to who knows what other reasons. You might also propose the idea of separately (and persistently) keeping track somewhere in the user profile of whether the desired folder structure was already created on a previous occasion, allowing the script to move on immediately if it has, but that is also insufficient because it could have, accidentally or otherwise, been deleted since then and now needs to be recreated.
So, bottom line my dev friends, what is really needed here is that some method be provided by the sync app for scripts to proactively query the status of the directory synchronization process, allowing them to delay their decisions until the sync has “officially” been completed. It’s a little frustrating to note that this information is already available to the user via the app’s tray icon tooltip or pop-up menu, but scripts have no access to it. The directory synchronization status needs to be made available programmatically, maybe as simply as setting a Registry entry, but feel free to choose whatever reasonable mechanism you like.
I for one would be grateful!
JB
Follow Jacques Bensimon on Twitter @JacqBens for more great Windows insights and tricks.