識別 macOS 上的託管文件夾 (Identify managed folders on macOS)


問題描述

識別 macOS 上的託管文件夾 (Identify managed folders on macOS)

如果我的客戶將 SQLite 數據庫放在託管文件夾中,我經常會遇到麻煩。對於託管文件夾,我的意思是:

  • 已安裝的捲
  • Dropbox文件夾
  • iCloud Drive文件夾
  • FUSE等
  • li>

是否有一種安全的方法來識別此類位置以警告用戶?


參考解法

方法 1:

Dropbox does offer a way to programmatically get the path of the local Dropbox folder(s) (if any):

https://help.dropbox.com/installs‑integrations/desktop/locate‑dropbox‑folder#programmatically

方法 2:

Based on the hint of @Greg I came up with a solution in ObjC using some private helpers, but I guess the idea should become clear:

‑ (BOOL)isDropbox:(NSURL *)url {
    // https://help.dropbox.com/de‑de/installs‑integrations/desktop/locate‑dropbox‑folder#programmatically
    id json = [[NSData dataWithContentsOfURL:hxFileURL(@"~/.dropbox/info.json".stringByExpandingTildeInPath)] fromJSON];
    NSString *ppath = json[@"personal"][@"path"];
    NSString *bpath = json[@"business"][@"path"];
    NSString *path = hxFilePath(url);
    return (ppath && [path hasPrefix:ppath]) || (bpath && [path hasPrefix:bpath]);
}

‑ (BOOL)hoIsLocal:(NSURL *)url {
    @try {
        if (![FS hoIsDir:url]) {
            url = [url URLByDeletingLastPathComponent];
        }

        // Is it local in general?
        ERROR_DEF;
        NSNumber *state;
        [url getResourceValue:&state forKey:NSURLVolumeIsLocalKey error:&error];
        XLogInfo(@"state=%@ url=%@", state, url);

        // If so it could be stored in iCloud Drive
        if (state.boolValue) {
            BOOL ubiq = [FS isUbiquitousItemAtURL:url];
            XLogInfo(@"ubiq=%@ url=%@", @(ubiq), url);

            // Or on Dropbox
            if (!ubiq) {
                BOOL dbx = [FS isDropbox:url];
                XLogInfo(@"dbx=%@ url=%@", @(dbx), url);
                return !dbx;
            }
        }
    }
    @catch (id ex) {
        XLogException(ex);
    }
    return NO;
}

(by HoltwickGregHoltwick)

參考文件

  1. Identify managed folders on macOS (CC BY‑SA 2.5/3.0/4.0)

#dropbox #synced-folder #icloud #directory #macos






相關問題

獲取 Dropbox 共享鏈接的文件列表 (Get list of files for dropbox shared link)

將文件上傳到保管箱時,方法出錯 (while uploading a file to dropbox getting an error with method)

Dropbox Api putFile php 發送文件失敗 (Dropbox Api putFile php fail send file)

Tiếp tục quá trình tải lên trong IOS nền (Continue uploading process in background IOS)

API Dropbox: phát hiện cập nhật tệp và nhận URL đến tệp? (Dropbox API: detect file updates, and get a URL to a file?)

Mac OS X 文件的 st_flags(用戶定義的標誌)是什麼? (What are st_flags (user defined flags) for a file Mac OS X?)

Dropbox如何監控? (How does dropbox monitoring?)

如何在 Dropbox 中使用 Bazaar? (How to use Bazaar with Dropbox?)

在 Python 中使用 OAuth2 連接到保管箱時出錯 (Error using OAuth2 to connect to dropbox in Python)

從樹莓派自動上傳到保管箱? (automatic upload on dropbox from raspberry pi?)

識別 macOS 上的託管文件夾 (Identify managed folders on macOS)

我們如何在下載/上傳 dropbbox 方法中獲取文件 mime-type/content-type? (How can we get files mime-type/content-type in download/upload dropbbox methods?)







留言討論