synapsepd / MacOS-OneDrive-KFM

MacOS OneDrive Known Folder Move (KFM)
Apache License 2.0
65 stars 11 forks source link

Files On-Demand? #6

Closed RiversideKid closed 4 years ago

RiversideKid commented 4 years ago

The current MacOS-OneDrive-KFM works great, but is there a supported way to enable Files On-Demand?

Currently I see the option to enable Files On-Demand, but when I click on Enable the OneDrive clients signs in again and the option is then not enabled. I would like this in the plist so that it is enabled by default.

Thank you.

lsethultra commented 4 years ago

This is also frustrating to me. Files on demand works until we run this script, but then after it's not just that it's turned off, but users can no longer turn it on. Very frustrating. I haven't been able to identify what causes this in the script.

samspade21 commented 4 years ago

That would be frustrating. We haven't seen this issue with our users. The script is not intended to "mess" with any FilesOnDemand settings. Are you using the AppStore version or the stand alone app? I have not tested the AppStore version. Also work validating you don't have a policy turning off FOD checking the output of: defaults read ~/Library/Preferences/com.microsoft.OneDrive.plist Maybe the AppStore version keeps preferences in a different location?

lsethultra commented 4 years ago

Also using the standalone version. No clues to be found in the plist. Even tried adding a setting to forcefully enable and it's still disabled and won't be enabled. The feature works before running the OneDrive-KFM script and then refuses to enable afterward. I've duplicated this on numerous systems running Mojave and Catalina.

Settings reference:

https://docs.microsoft.com/en-us/onedrive/deploy-and-configure-on-macos

Commands and results (private info x'd out):

defaults read ~/Library/Preferences/com.microsoft.OneDrive.plist
{
    BITApplicationDidEnterBackgroundTime = "1583525979.913621";
    BITApplicationWasLaunched = 1;
    HockeySDKAutomaticallySendCrashReports = 0;
    HockeySDKCrashReportActivated = 1;
    IsBusinessProvisioned = 1;
    NSOpenGLContextReplaceViewLayer = 0;
    OpenAtLogin = 1;
    Tenants =     {
        "xxxxx" =         {
            DefaultFolder = "xxxxx";
        };
    };
    UpdateRingSettingsLastSuccess = 18327;
}
defaults write ~/Library/Preferences/com.microsoft.OneDrive.plist FilesOnDemandEnabled 1
defaults read ~/Library/Preferences/com.microsoft.OneDrive.plist
{
    BITApplicationDidEnterBackgroundTime = "1583525979.913621";
    BITApplicationWasLaunched = 1;
    FilesOnDemandEnabled = 1;
    HockeySDKAutomaticallySendCrashReports = 0;
    HockeySDKCrashReportActivated = 1;
    IsBusinessProvisioned = 1;
    NSOpenGLContextReplaceViewLayer = 0;
    OpenAtLogin = 1;
    Tenants =     {
        "xxxxx" =         {
            DefaultFolder = "xxxxx";
        };
    };
    UpdateRingSettingsLastSuccess = 18327;
}
samspade21 commented 4 years ago

The only area that the script touches settings is the tenant ID in the plist. Maybe worth testing is a machine that has FOD working just fine, then close OneDrive and from a terminal run these commands (filling in the variables as appropriate). Then launch OneDrive again and see if the error is reproduced.

defaultTenantID="XXXXX"
defaultOneDriveFolder="/Users/joeuser/OneDrive - TennantName"
userHomeDirectory="/Users/joeuser"

/usr/libexec/PlistBuddy -c "Add :Tenants:$defaultTenantID:DefaultFolder string '$defaultOneDriveFolder'" "$userHomeDirectory/Library/Preferences/com.microsoft.OneDrive.plist"
lsethultra commented 4 years ago

Thanks for the tip! I was just looking at that very line and wondering how I could easily test it for culpability when you posted!

defaults read ~/Library/Preferences/com.microsoft.OneDrive.plist
{
    BITApplicationDidEnterBackgroundTime = "1583528824.533716";
    BITApplicationWasLaunched = 1;
    HockeySDKAutomaticallySendCrashReports = 0;
    HockeySDKCrashReportActivated = 1;
    IsBusinessProvisioned = 1;
    NSOpenGLContextReplaceViewLayer = 0;
    OpenAtLogin = 1;
}
defaults read ~/Library/Preferences/com.microsoft.OneDrive.plist
{
    BITApplicationDidEnterBackgroundTime = "1583528824.533716";
    BITApplicationWasLaunched = 1;
    HockeySDKAutomaticallySendCrashReports = 0;
    HockeySDKCrashReportActivated = 1;
    IsBusinessProvisioned = 1;
    NSOpenGLContextReplaceViewLayer = 0;
    OpenAtLogin = 1;
    Tenants =     {
        "xxxxx" =         {
            DefaultFolder = "xxxxx";
        };
    };
}

I don't know. I've got my eye on the "chown" commands in the login-privileged-every script. I'll try to test that next, but it may take me a while to read through the script and understand what all it's doing.

Please let me know if you have other suspicions I can test.

lsethultra commented 4 years ago

I have confirmed that the culprit is the rsync command, which merges files from the backup path into the OneDrive location. After you run that, close and re-open OneDrive, you can no longer turn on FoD. I'm looking at the syntax to see if I can figure out why it's the problem and hopefully figure out a way to fix it.

rsyncResults=$(rsync --checksum --remove-source-files --ignore-existing -avhE "$backupPath/" "$defaultOneDriveFolder/")

lsethultra commented 4 years ago

It looks like the issue is that FoD uses extended attributes (source: https://www.reddit.com/r/onedrive/comments/dk8hcx/onedrive_on_macos_is_adding_extendedfile/). By using rsync with the -E option, those extended attributes are stripped from the root OneDrive folder. I was able to solve it by breaking out the rsync into two commands, one for Desktop and one for Documents, instead of simply running it at the root folder.

Original:

rsyncResults=$(rsync --checksum --remove-source-files --ignore-existing -avhE "$backupPath/" "$defaultOneDriveFolder/")

Fixed:

rsyncResults=$(rsync --checksum --remove-source-files --ignore-existing -avhE "$backupPath/Desktop/" "$defaultOneDriveFolder/Desktop/"; rsync --checksum --remove-source-files --ignore-existing -avhE "$backupPath/Documents/" "$defaultOneDriveFolder/Documents/")

samspade21 commented 4 years ago

Great find. This has been tested and updated.