From patchwork Sat Sep 10 20:00:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12972683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2B21C6FA83 for ; Sat, 10 Sep 2022 20:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbiIJUCc (ORCPT ); Sat, 10 Sep 2022 16:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbiIJUCN (ORCPT ); Sat, 10 Sep 2022 16:02:13 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B574A135 for ; Sat, 10 Sep 2022 13:00:37 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id d2so8830116wrn.1 for ; Sat, 10 Sep 2022 13:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date; bh=sHgr0ryNjcOyPvUVkWinOPil5SWQgk91KyrA+Atn/3c=; b=RQBXWq/MpX/pM6XLLLM7p+zDR3YHlVkWFUYycZz2FzeYxahyNssXNgUW9BLzeXNvVH 8z8KvOKjdwnYMPGNGHbeQ9lSr+KU5cHklTUdh8/JDbG8ny49wUO/Qvzx8EZC8H/PwggS 6UA1lwlkvIbNMvd7WGWvSb3iQ+fHLA3oG5BeSqlQnlZtXP25TWAcwk3fhVT9D0yXTrUA 02bJPRd4zg9mGkjW0p+tH0hfqMvS5ALt8ZmeT24H2I9nRYuog63u0AQL+XzeGVBCTW6i z4ReBxV/k5V4sTASiugoHldm6M/KNSNHqgFE46HCFjjT6EnOERLH/SPEJSqcbziCOak6 D1EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date; bh=sHgr0ryNjcOyPvUVkWinOPil5SWQgk91KyrA+Atn/3c=; b=HjcPamTzrVrFlFPqjtaEaF6YGm3apuu27ZZiMFCS/d5KFg1tkyu6wOv5+U6b+w/To7 V62Ge2yLd7oIUv0QxjiG89BhG6ouMUjcplsgs6Lcf8wqfVRBX0QlsIpqIxhjq5aVJSKs zCu/VBHtQGi7hS3JQDSf31j+qsRS/c3x37Beetfvkw75r36U2gjyqT9k25svjzlWYThA Ce83vW/f7iqM3BsHWW00QFS7P3sRzi4DZm+FMMZPVdjdZmdF1GMZWpYQPGuRLcypzPC2 NXYRByGDBlxiBucLFat7Dl6CG1Zp/0v6OlKhWVfNMwGt933NDZ/iAAolKibf+BTHWVNh lXOw== X-Gm-Message-State: ACgBeo1IE/Pe53cPKBVmvpp7W59Lk6eazNHgj7obcHKYI2ebpm6HRxIq /PWz3Txu5TYO3LVwsgofOw2gI5vUki0= X-Google-Smtp-Source: AA6agR69Fw+nproePscVcZ2DRXtIZKIZAzqKlaTByeazLsANtIBKEnJNfYA0yCln3T018mEBCLz70A== X-Received: by 2002:adf:f44e:0:b0:22a:3b94:fdbd with SMTP id f14-20020adff44e000000b0022a3b94fdbdmr5426066wrp.647.1662840035110; Sat, 10 Sep 2022 13:00:35 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i3-20020a05600c354300b003a5ea1cc63csm5035814wmq.39.2022.09.10.13.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 13:00:34 -0700 (PDT) Message-Id: <2f647b53e4dcedece0c7ac1474afe9943cfd6be7.1662840031.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 10 Sep 2022 20:00:28 +0000 Subject: [PATCH v5 1/4] fsmonitor: refactor filesystem checks to common interface Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Eric Sunshine , Torsten =?utf-8?q?B=C3=B6gershause?= =?utf-8?q?n?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Ramsay Jones , Johannes Schindelin , Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Provide a common interface for getting basic filesystem information including filesystem type and whether the filesystem is remote. Refactor existing code for getting basic filesystem info and detecting remote file systems to the new interface. Refactor filesystem checks to leverage new interface. For macOS, error-out if the Unix Domain socket (UDS) file is on a remote filesystem. Signed-off-by: Eric DeCosta --- Makefile | 1 + compat/fsmonitor/fsm-path-utils-darwin.c | 40 +++++++++ compat/fsmonitor/fsm-path-utils-win32.c | 89 +++++++++++++++++++ compat/fsmonitor/fsm-settings-darwin.c | 62 ++++---------- compat/fsmonitor/fsm-settings-win32.c | 104 +---------------------- contrib/buildsystems/CMakeLists.txt | 2 + fsmonitor-path-utils.h | 23 +++++ fsmonitor-settings.c | 50 +++++++++++ 8 files changed, 224 insertions(+), 147 deletions(-) create mode 100644 compat/fsmonitor/fsm-path-utils-darwin.c create mode 100644 compat/fsmonitor/fsm-path-utils-win32.c create mode 100644 fsmonitor-path-utils.h diff --git a/Makefile b/Makefile index 924b864ae83..265fc585286 100644 --- a/Makefile +++ b/Makefile @@ -2042,6 +2042,7 @@ endif ifdef FSMONITOR_OS_SETTINGS COMPAT_CFLAGS += -DHAVE_FSMONITOR_OS_SETTINGS COMPAT_OBJS += compat/fsmonitor/fsm-settings-$(FSMONITOR_OS_SETTINGS).o + COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_OS_SETTINGS).o endif ifeq ($(TCLTK_PATH),) diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c new file mode 100644 index 00000000000..067cbe6990a --- /dev/null +++ b/compat/fsmonitor/fsm-path-utils-darwin.c @@ -0,0 +1,40 @@ +#include "fsmonitor.h" +#include "fsmonitor-path-utils.h" +#include +#include + +int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info) +{ + struct statfs fs; + if (statfs(path, &fs) == -1) { + int saved_errno = errno; + trace_printf_key(&trace_fsmonitor, "statfs('%s') failed: %s", + path, strerror(saved_errno)); + errno = saved_errno; + return -1; + } + + trace_printf_key(&trace_fsmonitor, + "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", + path, fs.f_type, fs.f_flags, fs.f_fstypename); + + if (!(fs.f_flags & MNT_LOCAL)) + fs_info->is_remote = 1; + else + fs_info->is_remote = 0; + + fs_info->typename = fs.f_fstypename; + + trace_printf_key(&trace_fsmonitor, + "'%s' is_remote: %d", + path, fs_info->is_remote); + return 0; +} + +int fsmonitor__is_fs_remote(const char *path) +{ + struct fs_info fs; + if (fsmonitor__get_fs_info(path, &fs)) + return -1; + return fs.is_remote; +} diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c new file mode 100644 index 00000000000..dc211de514f --- /dev/null +++ b/compat/fsmonitor/fsm-path-utils-win32.c @@ -0,0 +1,89 @@ +#include "cache.h" +#include "fsmonitor.h" +#include "fsmonitor-path-utils.h" + +/* + * Notes for testing: + * + * (a) Windows allows a network share to be mapped to a drive letter. + * (This is the normal method to access it.) + * + * $ NET USE Z: \\server\share + * $ git -C Z:/repo status + * + * (b) Windows allows a network share to be referenced WITHOUT mapping + * it to drive letter. + * + * $ NET USE \\server\share\dir + * $ git -C //server/share/repo status + * + * (c) Windows allows "SUBST" to create a fake drive mapping to an + * arbitrary path (which may be remote) + * + * $ SUBST Q: Z:\repo + * $ git -C Q:/ status + * + * (d) Windows allows a directory symlink to be created on a local + * file system that points to a remote repo. + * + * $ mklink /d ./link //server/share/repo + * $ git -C ./link status + */ +int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info) +{ + wchar_t wpath[MAX_PATH]; + wchar_t wfullpath[MAX_PATH]; + size_t wlen; + UINT driveType; + + /* + * Do everything in wide chars because the drive letter might be + * a multi-byte sequence. See win32_has_dos_drive_prefix(). + */ + if (xutftowcs_path(wpath, path) < 0) { + return -1; + } + + /* + * GetDriveTypeW() requires a final slash. We assume that the + * worktree pathname points to an actual directory. + */ + wlen = wcslen(wpath); + if (wpath[wlen - 1] != L'\\' && wpath[wlen - 1] != L'/') { + wpath[wlen++] = L'\\'; + wpath[wlen] = 0; + } + + /* + * Normalize the path. If nothing else, this converts forward + * slashes to backslashes. This is essential to get GetDriveTypeW() + * correctly handle some UNC "\\server\share\..." paths. + */ + if (!GetFullPathNameW(wpath, MAX_PATH, wfullpath, NULL)) { + return -1; + } + + driveType = GetDriveTypeW(wfullpath); + trace_printf_key(&trace_fsmonitor, + "DriveType '%s' L'%ls' (%u)", + path, wfullpath, driveType); + + if (driveType == DRIVE_REMOTE) + fs_info->is_remote = 1; + else + fs_info->is_remote = 0; + + trace_printf_key(&trace_fsmonitor, + "'%s' is_remote: %d", + path, fs_info->is_remote); + + return 0; +} + +int fsmonitor__is_fs_remote(const char *path) +{ + struct fs_info fs; + if (fsmonitor__get_fs_info(path, &fs)) + return -1; + return fs.is_remote; +} diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index efc732c0f31..dba3ced6bb7 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -1,32 +1,10 @@ -#include "cache.h" #include "config.h" -#include "repository.h" -#include "fsmonitor-settings.h" #include "fsmonitor.h" -#include -#include +#include "fsmonitor-ipc.h" +#include "fsmonitor-settings.h" +#include "fsmonitor-path-utils.h" -/* - * [1] Remote working directories are problematic for FSMonitor. - * - * The underlying file system on the server machine and/or the remote - * mount type (NFS, SAMBA, etc.) dictates whether notification events - * are available at all to remote client machines. - * - * Kernel differences between the server and client machines also - * dictate the how (buffering, frequency, de-dup) the events are - * delivered to client machine processes. - * - * A client machine (such as a laptop) may choose to suspend/resume - * and it is unclear (without lots of testing) whether the watcher can - * resync after a resume. We might be able to treat this as a normal - * "events were dropped by the kernel" event and do our normal "flush - * and resync" --or-- we might need to close the existing (zombie?) - * notification fd and create a new one. - * - * In theory, the above issues need to be addressed whether we are - * using the Hook or IPC API. - * + /* * For the builtin FSMonitor, we create the Unix domain socket for the * IPC in the .git directory. If the working directory is remote, * then the socket will be created on the remote file system. This @@ -38,40 +16,34 @@ * be taken to ensure that $HOME is actually local and not a managed * file share.) * - * So (for now at least), mark remote working directories as - * incompatible. - * - * - * [2] FAT32 and NTFS working directories are problematic too. + * FAT32 and NTFS working directories are problematic too. * * The builtin FSMonitor uses a Unix domain socket in the .git * directory for IPC. These Windows drive formats do not support * Unix domain sockets, so mark them as incompatible for the daemon. * */ -static enum fsmonitor_reason check_volume(struct repository *r) +static enum fsmonitor_reason check_uds_volume(struct repository *r) { - struct statfs fs; + struct fs_info fs; + const char *ipc_path = fsmonitor_ipc__get_path(); + struct strbuf path = STRBUF_INIT; + strbuf_add(&path, ipc_path, strlen(ipc_path)); - if (statfs(r->worktree, &fs) == -1) { - int saved_errno = errno; - trace_printf_key(&trace_fsmonitor, "statfs('%s') failed: %s", - r->worktree, strerror(saved_errno)); - errno = saved_errno; + if (fsmonitor__get_fs_info(dirname(path.buf), &fs) == -1) { + strbuf_release(&path); return FSMONITOR_REASON_ERROR; } - trace_printf_key(&trace_fsmonitor, - "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", - r->worktree, fs.f_type, fs.f_flags, fs.f_fstypename); + strbuf_release(&path); - if (!(fs.f_flags & MNT_LOCAL)) + if (fs.is_remote) return FSMONITOR_REASON_REMOTE; - if (!strcmp(fs.f_fstypename, "msdos")) /* aka FAT32 */ + if (!strcmp(fs.typename, "msdos")) /* aka FAT32 */ return FSMONITOR_REASON_NOSOCKETS; - if (!strcmp(fs.f_fstypename, "ntfs")) + if (!strcmp(fs.typename, "ntfs")) return FSMONITOR_REASON_NOSOCKETS; return FSMONITOR_REASON_OK; @@ -81,7 +53,7 @@ enum fsmonitor_reason fsm_os__incompatible(struct repository *r) { enum fsmonitor_reason reason; - reason = check_volume(r); + reason = check_uds_volume(r); if (reason != FSMONITOR_REASON_OK) return reason; diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c index 907655720bb..d88b06ae610 100644 --- a/compat/fsmonitor/fsm-settings-win32.c +++ b/compat/fsmonitor/fsm-settings-win32.c @@ -1,8 +1,9 @@ #include "cache.h" #include "config.h" #include "repository.h" -#include "fsmonitor-settings.h" #include "fsmonitor.h" +#include "fsmonitor-settings.h" +#include "fsmonitor-path-utils.h" /* * VFS for Git is incompatible with FSMonitor. @@ -24,103 +25,6 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r) return FSMONITOR_REASON_OK; } -/* - * Remote working directories are problematic for FSMonitor. - * - * The underlying file system on the server machine and/or the remote - * mount type dictates whether notification events are available at - * all to remote client machines. - * - * Kernel differences between the server and client machines also - * dictate the how (buffering, frequency, de-dup) the events are - * delivered to client machine processes. - * - * A client machine (such as a laptop) may choose to suspend/resume - * and it is unclear (without lots of testing) whether the watcher can - * resync after a resume. We might be able to treat this as a normal - * "events were dropped by the kernel" event and do our normal "flush - * and resync" --or-- we might need to close the existing (zombie?) - * notification fd and create a new one. - * - * In theory, the above issues need to be addressed whether we are - * using the Hook or IPC API. - * - * So (for now at least), mark remote working directories as - * incompatible. - * - * Notes for testing: - * - * (a) Windows allows a network share to be mapped to a drive letter. - * (This is the normal method to access it.) - * - * $ NET USE Z: \\server\share - * $ git -C Z:/repo status - * - * (b) Windows allows a network share to be referenced WITHOUT mapping - * it to drive letter. - * - * $ NET USE \\server\share\dir - * $ git -C //server/share/repo status - * - * (c) Windows allows "SUBST" to create a fake drive mapping to an - * arbitrary path (which may be remote) - * - * $ SUBST Q: Z:\repo - * $ git -C Q:/ status - * - * (d) Windows allows a directory symlink to be created on a local - * file system that points to a remote repo. - * - * $ mklink /d ./link //server/share/repo - * $ git -C ./link status - */ -static enum fsmonitor_reason check_remote(struct repository *r) -{ - wchar_t wpath[MAX_PATH]; - wchar_t wfullpath[MAX_PATH]; - size_t wlen; - UINT driveType; - - /* - * Do everything in wide chars because the drive letter might be - * a multi-byte sequence. See win32_has_dos_drive_prefix(). - */ - if (xutftowcs_path(wpath, r->worktree) < 0) - return FSMONITOR_REASON_ERROR; - - /* - * GetDriveTypeW() requires a final slash. We assume that the - * worktree pathname points to an actual directory. - */ - wlen = wcslen(wpath); - if (wpath[wlen - 1] != L'\\' && wpath[wlen - 1] != L'/') { - wpath[wlen++] = L'\\'; - wpath[wlen] = 0; - } - - /* - * Normalize the path. If nothing else, this converts forward - * slashes to backslashes. This is essential to get GetDriveTypeW() - * correctly handle some UNC "\\server\share\..." paths. - */ - if (!GetFullPathNameW(wpath, MAX_PATH, wfullpath, NULL)) - return FSMONITOR_REASON_ERROR; - - driveType = GetDriveTypeW(wfullpath); - trace_printf_key(&trace_fsmonitor, - "DriveType '%s' L'%ls' (%u)", - r->worktree, wfullpath, driveType); - - if (driveType == DRIVE_REMOTE) { - trace_printf_key(&trace_fsmonitor, - "check_remote('%s') true", - r->worktree); - return FSMONITOR_REASON_REMOTE; - } - - return FSMONITOR_REASON_OK; -} - enum fsmonitor_reason fsm_os__incompatible(struct repository *r) { enum fsmonitor_reason reason; @@ -129,9 +33,5 @@ enum fsmonitor_reason fsm_os__incompatible(struct repository *r) if (reason != FSMONITOR_REASON_OK) return reason; - reason = check_remote(r); - if (reason != FSMONITOR_REASON_OK) - return reason; - return FSMONITOR_REASON_OK; } diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 2237109b57f..b88494bf59b 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -308,6 +308,7 @@ if(SUPPORTS_SIMPLE_IPC) add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c) add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c) @@ -315,6 +316,7 @@ if(SUPPORTS_SIMPLE_IPC) add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c) add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c) diff --git a/fsmonitor-path-utils.h b/fsmonitor-path-utils.h new file mode 100644 index 00000000000..e48592887e7 --- /dev/null +++ b/fsmonitor-path-utils.h @@ -0,0 +1,23 @@ +#ifndef FSM_PATH_UTILS_H +#define FSM_PATH_UTILS_H + +struct fs_info { + int is_remote; + char *typename; +}; + +/* + * Get some basic filesystem informtion for the given path + * + * Returns -1 on error, zero otherwise. + */ +int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info); + +/* + * Determines if the filesystem that path resides on is remote. + * + * Returns -1 on error, 0 if not remote, 1 if remote. + */ +int fsmonitor__is_fs_remote(const char *path); + +#endif diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 464424a1e92..d288cbad479 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -2,6 +2,7 @@ #include "config.h" #include "repository.h" #include "fsmonitor-settings.h" +#include "fsmonitor-path-utils.h" /* * We keep this structure defintion private and have getters @@ -13,6 +14,52 @@ struct fsmonitor_settings { char *hook_path; }; +/* + * Remote working directories are problematic for FSMonitor. + * + * The underlying file system on the server machine and/or the remote + * mount type dictates whether notification events are available at + * all to remote client machines. + * + * Kernel differences between the server and client machines also + * dictate the how (buffering, frequency, de-dup) the events are + * delivered to client machine processes. + * + * A client machine (such as a laptop) may choose to suspend/resume + * and it is unclear (without lots of testing) whether the watcher can + * resync after a resume. We might be able to treat this as a normal + * "events were dropped by the kernel" event and do our normal "flush + * and resync" --or-- we might need to close the existing (zombie?) + * notification fd and create a new one. + * + * In theory, the above issues need to be addressed whether we are + * using the Hook or IPC API. + * + * So (for now at least), mark remote working directories as + * incompatible unless 'fsmonitor.allowRemote' is true. + * + */ +#ifdef HAVE_FSMONITOR_OS_SETTINGS +static enum fsmonitor_reason check_remote(struct repository *r) +{ + int allow_remote = -1; /* -1 unset, 0 not allowed, 1 allowed */ + int is_remote = fsmonitor__is_fs_remote(r->worktree); + + switch (is_remote) { + case 0: + return FSMONITOR_REASON_OK; + case 1: + repo_config_get_bool(r, "fsmonitor.allowremote", &allow_remote); + if (allow_remote < 1) + return FSMONITOR_REASON_REMOTE; + else + return FSMONITOR_REASON_OK; + default: + return FSMONITOR_REASON_ERROR; + } +} +#endif + static enum fsmonitor_reason check_for_incompatible(struct repository *r) { if (!r->worktree) { @@ -27,6 +74,9 @@ static enum fsmonitor_reason check_for_incompatible(struct repository *r) { enum fsmonitor_reason reason; + reason = check_remote(r); + if (reason != FSMONITOR_REASON_OK) + return reason; reason = fsm_os__incompatible(r); if (reason != FSMONITOR_REASON_OK) return reason; From patchwork Sat Sep 10 20:00:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12972685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 198BEECAAD3 for ; Sat, 10 Sep 2022 20:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbiIJUCe (ORCPT ); Sat, 10 Sep 2022 16:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbiIJUCQ (ORCPT ); Sat, 10 Sep 2022 16:02:16 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57047BE37 for ; Sat, 10 Sep 2022 13:00:37 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id n17-20020a05600c3b9100b003b3235574dbso4225056wms.2 for ; Sat, 10 Sep 2022 13:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date; bh=Hv/cPzF/fvyiQwf4EpBftGXrXXIIzkQVDoj6j7X7gus=; b=KwTXV7/S1Krn3h+jEjsdSat9c7Mhr2m2eHJDFOHEuxOP15H509TCQO7lAQa0YGgY2F 99xsqpUEvxKXmQqWH5sTrosumEoBHExy0RgN/4FYjow0ZrFHKXi2jWKm5O+iAeJ21ATb PuPIDl17RmWdHCLXUfP6AmDqJecLI0NbLneHdtoijd+SRcoXjKOYS4fOB53j1FoDfl9H mY4NygCZ6fWUIllxmWnuSGVC/zF1Zlt3mDwP4RgLa4X0no0SqmcllZdZMkWAvXucMH6/ eI4bGRS9gH8eh4WJvcgMmfOnDDxqEqyKQmBzKrIHP46DhwWX0vGwzOXJbvuQAybD+JcN YU8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date; bh=Hv/cPzF/fvyiQwf4EpBftGXrXXIIzkQVDoj6j7X7gus=; b=zklOc4nQHPc/exP9wNdVbK+x+THspjilO6IBhF1Xaj3YwU2MmQWXFiVHOqaNIV13/F lBbUmm4oAV0iLLbeHK9YAbwJUDiG1opjDGE63FHyZKi3WNgQSnWdj/ZZ5mPI/GBwRi0E i12Vtw5LZkQnAB/xS4DfTaIAdAEpwV02HGKWKA5TbJQnR1JqPq6IVDU8rzWb3WUJDg/L R4KDKJl19JhFdCcJlz00k4gIpVsmuyCzQqKWlGlgzVu8pJ8AXEH5cGlgTNJqe9+kzU1h nF4lT1uvxdobMgZhVlF1KY3YvFPJdgty8n7Tn6U3UcUpXHNT08EheeWwuBJE7xe2VnEM E6Yw== X-Gm-Message-State: ACgBeo2Md2WeFOS+p2/9tiMywZGXBD2LUBvxIob3RK9JoTT/3RsskL5Y kDA9HGMLZS/xxFYBJX7Xip3xD+Sbbq0= X-Google-Smtp-Source: AA6agR4YfB8g41Y6O10yTclgQlg9xPyFxyM7VczyDzVDNW8MH/nzNgEczYClBVJLi1ze/jxzkN1cKA== X-Received: by 2002:a05:600c:3b07:b0:3b3:3ec4:6ccb with SMTP id m7-20020a05600c3b0700b003b33ec46ccbmr7046634wms.69.1662840036285; Sat, 10 Sep 2022 13:00:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t16-20020adfe110000000b00229b76f872asm4080059wrz.27.2022.09.10.13.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 13:00:35 -0700 (PDT) Message-Id: <28d08bcf80810f0453c9c9ff03d45dd0e5795961.1662840031.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 10 Sep 2022 20:00:29 +0000 Subject: [PATCH v5 2/4] fsmonitor: relocate socket file if .git directory is remote Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Eric Sunshine , Torsten =?utf-8?q?B=C3=B6gershause?= =?utf-8?q?n?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Ramsay Jones , Johannes Schindelin , Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta If the .git directory is on a remote file system, create the socket file in 'fsmonitor.socketDir' if it is defined, else create it in $HOME. Signed-off-by: Eric DeCosta --- Makefile | 1 + compat/fsmonitor/fsm-ipc-darwin.c | 46 +++++++++++++++++++++++++++++ compat/fsmonitor/fsm-ipc-win32.c | 4 +++ contrib/buildsystems/CMakeLists.txt | 2 ++ fsmonitor-ipc.c | 2 -- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 compat/fsmonitor/fsm-ipc-darwin.c create mode 100644 compat/fsmonitor/fsm-ipc-win32.c diff --git a/Makefile b/Makefile index 265fc585286..cf9c51040a0 100644 --- a/Makefile +++ b/Makefile @@ -2037,6 +2037,7 @@ ifdef FSMONITOR_DAEMON_BACKEND COMPAT_CFLAGS += -DHAVE_FSMONITOR_DAEMON_BACKEND COMPAT_OBJS += compat/fsmonitor/fsm-listen-$(FSMONITOR_DAEMON_BACKEND).o COMPAT_OBJS += compat/fsmonitor/fsm-health-$(FSMONITOR_DAEMON_BACKEND).o + COMPAT_OBJS += compat/fsmonitor/fsm-ipc-$(FSMONITOR_DAEMON_BACKEND).o endif ifdef FSMONITOR_OS_SETTINGS diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c new file mode 100644 index 00000000000..afaca96dab9 --- /dev/null +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -0,0 +1,46 @@ +#include "cache.h" +#include "config.h" +#include "strbuf.h" +#include "fsmonitor.h" +#include "fsmonitor-ipc.h" +#include "fsmonitor-path-utils.h" + +static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc") + +const char *fsmonitor_ipc__get_path(void) +{ + static const char *ipc_path; + SHA_CTX sha1ctx; + char *sock_dir; + struct strbuf ipc_file = STRBUF_INIT; + unsigned char hash[SHA_DIGEST_LENGTH]; + + if (ipc_path) + return ipc_path; + + ipc_path = fsmonitor_ipc__get_default_path(); + + /* By default the socket file is created in the .git directory */ + if (fsmonitor__is_fs_remote(ipc_path) < 1) + return ipc_path; + + SHA1_Init(&sha1ctx); + SHA1_Update(&sha1ctx, the_repository->worktree, strlen(the_repository->worktree)); + SHA1_Final(hash, &sha1ctx); + + repo_config_get_string(the_repository, "fsmonitor.socketdir", &sock_dir); + + /* Create the socket file in either socketDir or $HOME */ + if (sock_dir && *sock_dir) + strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s", + sock_dir, hash_to_hex(hash)); + else + strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash)); + + ipc_path = interpolate_path(ipc_file.buf, 1); + if (!ipc_path) + die(_("Invalid path: %s"), ipc_file.buf); + + strbuf_release(&ipc_file); + return ipc_path; +} diff --git a/compat/fsmonitor/fsm-ipc-win32.c b/compat/fsmonitor/fsm-ipc-win32.c new file mode 100644 index 00000000000..769a88639f6 --- /dev/null +++ b/compat/fsmonitor/fsm-ipc-win32.c @@ -0,0 +1,4 @@ +#include "cache.h" +#include "fsmonitor-ipc.h" + +GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc") diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index b88494bf59b..7e7b6b9a362 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -308,6 +308,7 @@ if(SUPPORTS_SIMPLE_IPC) add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c) add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) @@ -316,6 +317,7 @@ if(SUPPORTS_SIMPLE_IPC) add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-darwin.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c) add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 789e7397baa..caad2e246a0 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -47,8 +47,6 @@ int fsmonitor_ipc__is_supported(void) return 1; } -GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc") - enum ipc_active_state fsmonitor_ipc__get_state(void) { return ipc_get_active_state(fsmonitor_ipc__get_path()); From patchwork Sat Sep 10 20:00:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12972686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65688C6FA83 for ; Sat, 10 Sep 2022 20:02:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbiIJUCg (ORCPT ); Sat, 10 Sep 2022 16:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbiIJUCQ (ORCPT ); Sat, 10 Sep 2022 16:02:16 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D675476ED for ; Sat, 10 Sep 2022 13:00:39 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k9so8871079wri.0 for ; Sat, 10 Sep 2022 13:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date; bh=oFZbG9WkdiUYulw81PCz1BIFi8UiLOlwTp2wvCZ4/po=; b=d3ayhQNAGc2iC/LpiV/I1Fcughsj/C9FA/NupCoMwxI8g9Y1+ml5UzQ/QFCyUEATSW 7FT3V+st98N3rXrfoNMUcslnSe8682lD8DUANbYzFwnPtJEO5HgXNsjZTc+dO+Wkpl0n lFhwGTmaXJDjmLDUi3AE3vDFqjZ3SVbmIbb5BNCUBBxwHK5doi1XElviX9WWGkIKwmll YD+9hh2AhBFf6oc2kc19d3PpWkKA71VuYR4ZXzIls3S5FJvz01TVByJkzwi1ectUPD0N 80qr/EdYtSbe/7kWM3EaHtrGuVkG6n5aCQIbIOfYOzqr+WxahssGXvR2iLuYoF+2cliJ 5JBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date; bh=oFZbG9WkdiUYulw81PCz1BIFi8UiLOlwTp2wvCZ4/po=; b=ZEnPWW4ON1fM0Rck3j64MBhovKe8fjUreo3z+ksgoAMfCPzTQc9Q6PTmMoeFSa15pG d1z+6JAJa3OPINzSUpXx3tTmw1QiRD94f74z4gspMjRYI+YAKTP9O34NaGFKe0fGrZyr eLR6D3FNDvpda2vKVPK4OlU5G8Ehps+vLLgpxSEq3f3MV8BB4ymQLe5u3+hKDlHj6YX6 uIEk3I9jj8BP4wCNnZaWC9Oy5pdNlUPpAkPF27RgX1ZhISxSA3+iHMrgap/iNwp8Uux7 BDB/pXyTDqLxyhrXN0DsmMjutj0Aw1g9o2ycszIAdLtTCZrrq8oJr3Fe2jtFxpOBMRLL 8PCQ== X-Gm-Message-State: ACgBeo3I5G6pU8XfuKgiXIVaq6TqOqQoHQzP5vwgoihrSaXpsJ46z2vG QMhVRvyIikcBT8ikmGq2BrUQ2hVLEMo= X-Google-Smtp-Source: AA6agR5SuJg/fdhJYC1OIOsJ+tFzVjiJwlW7CG8i2jD7HDSm5W7ezFa0v2xjDL77W+1X2eYePWrmOw== X-Received: by 2002:a05:6000:2cd:b0:22a:4831:dfd with SMTP id o13-20020a05600002cd00b0022a48310dfdmr2160392wry.706.1662840037278; Sat, 10 Sep 2022 13:00:37 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v8-20020a05600c12c800b003a844885f88sm4275091wmd.22.2022.09.10.13.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 13:00:36 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 10 Sep 2022 20:00:30 +0000 Subject: [PATCH v5 3/4] fsmonitor: avoid socket location check if using hook Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Eric Sunshine , Torsten =?utf-8?q?B=C3=B6gershause?= =?utf-8?q?n?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Ramsay Jones , Johannes Schindelin , Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta If monitoring is done via fsmonitor hook rather than IPC there is no need to check if the location of the Unix Domain socket (UDS) file is on a remote filesystem. Signed-off-by: Eric DeCosta --- compat/fsmonitor/fsm-settings-darwin.c | 10 ++++++---- compat/fsmonitor/fsm-settings-win32.c | 2 +- fsmonitor-settings.c | 8 ++++---- fsmonitor-settings.h | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index dba3ced6bb7..3463c71763e 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -49,13 +49,15 @@ static enum fsmonitor_reason check_uds_volume(struct repository *r) return FSMONITOR_REASON_OK; } -enum fsmonitor_reason fsm_os__incompatible(struct repository *r) +enum fsmonitor_reason fsm_os__incompatible(struct repository *r, int ipc) { enum fsmonitor_reason reason; - reason = check_uds_volume(r); - if (reason != FSMONITOR_REASON_OK) - return reason; + if (ipc) { + reason = check_uds_volume(r); + if (reason != FSMONITOR_REASON_OK) + return reason; + } return FSMONITOR_REASON_OK; } diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c index d88b06ae610..a8af31b71de 100644 --- a/compat/fsmonitor/fsm-settings-win32.c +++ b/compat/fsmonitor/fsm-settings-win32.c @@ -25,7 +25,7 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r) return FSMONITOR_REASON_OK; } -enum fsmonitor_reason fsm_os__incompatible(struct repository *r) +enum fsmonitor_reason fsm_os__incompatible(struct repository *r, int ipc) { enum fsmonitor_reason reason; diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index d288cbad479..531a1b6f956 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -60,7 +60,7 @@ static enum fsmonitor_reason check_remote(struct repository *r) } #endif -static enum fsmonitor_reason check_for_incompatible(struct repository *r) +static enum fsmonitor_reason check_for_incompatible(struct repository *r, int ipc) { if (!r->worktree) { /* @@ -77,7 +77,7 @@ static enum fsmonitor_reason check_for_incompatible(struct repository *r) reason = check_remote(r); if (reason != FSMONITOR_REASON_OK) return reason; - reason = fsm_os__incompatible(r); + reason = fsm_os__incompatible(r, ipc); if (reason != FSMONITOR_REASON_OK) return reason; } @@ -162,7 +162,7 @@ const char *fsm_settings__get_hook_path(struct repository *r) void fsm_settings__set_ipc(struct repository *r) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason = check_for_incompatible(r, 1); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); @@ -185,7 +185,7 @@ void fsm_settings__set_ipc(struct repository *r) void fsm_settings__set_hook(struct repository *r, const char *path) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason = check_for_incompatible(r, 0); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); diff --git a/fsmonitor-settings.h b/fsmonitor-settings.h index d9c2605197f..0721617b95a 100644 --- a/fsmonitor-settings.h +++ b/fsmonitor-settings.h @@ -48,7 +48,7 @@ struct fsmonitor_settings; * fsm_os__* routines should considered private to fsm_settings__ * routines. */ -enum fsmonitor_reason fsm_os__incompatible(struct repository *r); +enum fsmonitor_reason fsm_os__incompatible(struct repository *r, int ipc); #endif /* HAVE_FSMONITOR_OS_SETTINGS */ #endif /* FSMONITOR_SETTINGS_H */ From patchwork Sat Sep 10 20:00:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12972687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CBA5ECAAD3 for ; Sat, 10 Sep 2022 20:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbiIJUCs (ORCPT ); Sat, 10 Sep 2022 16:02:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbiIJUCR (ORCPT ); Sat, 10 Sep 2022 16:02:17 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 408AC4CA37 for ; Sat, 10 Sep 2022 13:00:40 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id b5so8796157wrr.5 for ; Sat, 10 Sep 2022 13:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date; bh=2xTdcA64T5fsLpr6jfslMo1bzEjJhpSDuoIBKlYqSKA=; b=dETlUOjxq2J0VrnJaTmWj7Ohu0ahRzQ2xXgjXt8HtIhi+62mqpju+HJ6f5XCcERBu8 GKFuFfoIlIX/X05Z6irpOUIVwp+1cUzyR1MRYXjp6rvbiRPKgIgl1n+gQk/9uJmpcF3I GooZ3pBx2/oGhuZ1Vd6MhypN1mLsoD6lhQbAAFjqBJhKnIRpHM7oelAo/7eSX1/95oOk D5MDYlCjnSIXpnuC1e1pPeY+YchOLwu0Jh64AbVDmeyW+MNMhZJ2hMWWV5M9L5PALqrZ 7PcKqghQEOaEX4bMoTCWj86xLa4oIM5D8W3KJ0V+b6idKPV/jJgowVwaZW2r6t3+wyxn gPOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date; bh=2xTdcA64T5fsLpr6jfslMo1bzEjJhpSDuoIBKlYqSKA=; b=In4Exybajw5hPmrcA0KPYtziqXYI7SGV7YmdzL7ItL0hKEJv0R9Yfqr7+A7leQZfjS d52gg4I07FCqMTa8m5dBVNziz9QJSAPAs0LyaCSeobEU+axrDmx3sFiJCR1OM6Rp1vkt 34QiQ1J9nEjwLEWsFu7iSjw9ZpJPWHalhOVCxYXgqcfguOdpKyvLa8AcTq+kHGw57qaL AMqHZepCDXQTnOFWV7ARwNY7bnY02NO0vUwubq34HWwlHnRRm5mQMeMEw258dIUbk04v 4Ae5lHhvCncB7HnDJT9e3c7V+w0L8kBcP7u39TpHt4lb5GBxaeKTq/Xfb6gv4rKBRf08 dW+g== X-Gm-Message-State: ACgBeo0lMjVhDeiDBpTcKLzZF7Ge65FIU0+KSilznlE5hIWYqJFzDujz sTcHimRoQi23RD1pLL+RVjTyCaKq2r4= X-Google-Smtp-Source: AA6agR5Gp/ixTM7Xgau5uJ6ItaJeLAbrdiyT08715ijYCGvXqmaMbSiovYtOHo2kKqOYgoIi6kGvFQ== X-Received: by 2002:a05:6000:80a:b0:229:4632:d1d1 with SMTP id bt10-20020a056000080a00b002294632d1d1mr11029584wrb.73.1662840038181; Sat, 10 Sep 2022 13:00:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w21-20020a1cf615000000b003a63a3b55c3sm4536803wmc.14.2022.09.10.13.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 13:00:37 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 10 Sep 2022 20:00:31 +0000 Subject: [PATCH v5 4/4] fsmonitor: deal with synthetic firmlinks on macOS Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Eric Sunshine , Torsten =?utf-8?q?B=C3=B6gershause?= =?utf-8?q?n?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Ramsay Jones , Johannes Schindelin , Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Starting with macOS 10.15 (Catalina), Apple introduced a new feature called 'firmlinks' in order to separate the boot volume into two volumes, one read-only and one writable but still present them to the user as a single volume. Along with this change, Apple removed the ability to create symlinks in the root directory and replaced them with 'synthetic firmlinks'. See 'man synthetic.conf' When FSEevents reports the path of changed files, if the path invloves a synthetic firmlink, the path is reported from the point of the synthetic firmlink and not the real path. For example: Real path: /System/Volumes/Data/network/working/directory/foo.txt Synthetic firmlink: /network -> /System/Volumes/Data/network FSEvents path: /network/working/directory/foo.txt This causes the FSEvents path to not match against the worktree directory. There are several ways in which synthetic firmlinks can be created: they can be defined in /etc/synthetic.conf, the automounter can create them, and there may be other means. Simply reading /etc/synthetic.conf is insufficient. No matter what process creates synthetic firmlinks, they all get created in the root directory. Therefore, in order to deal with synthetic firmlinks, the root directory is scanned and the first possible synthetic firmink that, when resolved, is a prefix of the worktree is used to map FSEvents paths to worktree paths. Signed-off-by: Eric DeCosta --- builtin/fsmonitor--daemon.c | 8 +++ compat/fsmonitor/fsm-listen-darwin.c | 6 +- compat/fsmonitor/fsm-path-utils-darwin.c | 91 ++++++++++++++++++++++++ compat/fsmonitor/fsm-path-utils-win32.c | 17 +++++ fsmonitor--daemon.h | 6 ++ fsmonitor-path-utils.h | 26 +++++++ 6 files changed, 153 insertions(+), 1 deletion(-) diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 2c109cf8b37..2559150d9e7 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -3,6 +3,7 @@ #include "parse-options.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" +#include "fsmonitor-path-utils.h" #include "compat/fsmonitor/fsm-health.h" #include "compat/fsmonitor/fsm-listen.h" #include "fsmonitor--daemon.h" @@ -1282,6 +1283,13 @@ static int fsmonitor_run_daemon(void) strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree())); state.nr_paths_watching = 1; + strbuf_init(&state.alias.alias, 0); + strbuf_init(&state.alias.points_to, 0); + if (fsmonitor__get_alias(state.path_worktree_watch.buf, &state.alias)) { + err = error(_("could not get worktree alias")); + goto done; + } + /* * We create and delete cookie files somewhere inside the .git * directory to help us keep sync with the file system. If diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index 8e208e8289e..179886bc15b 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -26,6 +26,7 @@ #include "fsmonitor.h" #include "fsm-listen.h" #include "fsmonitor--daemon.h" +#include "fsmonitor-path-utils.h" struct fsm_listen_data { @@ -209,7 +210,9 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, /* * On Mac, we receive an array of absolute paths. */ - path_k = paths[k]; + path_k = fsmonitor__resolve_alias(paths[k], &state->alias); + if (!path_k) + path_k = paths[k]; /* * If you want to debug FSEvents, log them to GIT_TRACE_FSMONITOR. @@ -238,6 +241,7 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, fsmonitor_force_resync(state); fsmonitor_batch__free_list(batch); string_list_clear(&cookie_list, 0); + batch = NULL; /* * We assume that any events that we received diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c index 067cbe6990a..1f1550c485a 100644 --- a/compat/fsmonitor/fsm-path-utils-darwin.c +++ b/compat/fsmonitor/fsm-path-utils-darwin.c @@ -1,5 +1,8 @@ #include "fsmonitor.h" #include "fsmonitor-path-utils.h" +#include +#include +#include #include #include @@ -38,3 +41,91 @@ int fsmonitor__is_fs_remote(const char *path) return -1; return fs.is_remote; } + +/* + * Scan the root directory for synthetic firmlinks that when resolved + * are a prefix of the path, stopping at the first one found. + * + * Some information about firmlinks and synthetic firmlinks: + * https://eclecticlight.co/2020/01/23/catalina-boot-volumes/ + * + * macOS no longer allows symlinks in the root directory; any link found + * there is therefore a synthetic firmlink. + * + * If this function gets called often, will want to cache all the firmlink + * information, but for now there is only one caller of this function. + * + * If there is more than one alias for the path, that is another + * matter altogteher. + */ +int fsmonitor__get_alias(const char *path, struct alias_info *info) +{ + DIR * dir; + int read; + int retval; + struct dirent *de; + struct strbuf alias; + struct strbuf points_to; + + retval = 0; + dir = opendir("/"); + if (!dir) + return -1; + + strbuf_init(&alias, 256); + strbuf_init(&points_to, MAXPATHLEN); + + while ((de = readdir(dir)) != NULL) { + strbuf_reset(&alias); + strbuf_addch(&alias, '/'); + strbuf_add(&alias, de->d_name, strlen(de->d_name)); + + read = readlink(alias.buf, points_to.buf, MAXPATHLEN); + if (read > 0) { + strbuf_setlen(&points_to, read); + if ((strncmp(points_to.buf, path, points_to.len) == 0) + && path[points_to.len] == '/') { + strbuf_addbuf(&info->alias, &alias); + strbuf_addbuf(&info->points_to, &points_to); + trace_printf_key(&trace_fsmonitor, + "Found alias for '%s' : '%s' -> '%s'", + path, info->alias.buf, info->points_to.buf); + retval = 0; + goto done; + } + } else if (errno != EINVAL) { /* Something other than not a link */ + trace_printf_key(&trace_fsmonitor, "Error %s", strerror(errno)); + retval = -1; + goto done; + } + } + + done: + closedir(dir); + strbuf_release(&alias); + strbuf_release(&points_to); + return retval; +} + +char *fsmonitor__resolve_alias(const char *path, + const struct alias_info *info) +{ + int len = info->alias.len; + + if (!len) + return NULL; + + if ((strncmp(info->alias.buf, path, len) == 0) + && path[len] == '/') { + struct strbuf tmp; + const char *remainder = path + len; + int rem_len = strlen(remainder); + + strbuf_init(&tmp, info->points_to.len + rem_len); + strbuf_addbuf(&tmp, &info->points_to); + strbuf_add(&tmp, remainder, rem_len); + return strbuf_detach(&tmp, NULL); + } + + return NULL; +} diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c index dc211de514f..0ca366bfe08 100644 --- a/compat/fsmonitor/fsm-path-utils-win32.c +++ b/compat/fsmonitor/fsm-path-utils-win32.c @@ -87,3 +87,20 @@ int fsmonitor__is_fs_remote(const char *path) return -1; return fs.is_remote; } + +/* + * No-op for now. + */ +int fsmonitor__get_alias(const char *path, struct alias_info *info) +{ + return 0; +} + +/* + * No-op for now. + */ +char *fsmonitor__resolve_alias(const char *path, + const struct alias_info *info) +{ + return NULL; +} diff --git a/fsmonitor--daemon.h b/fsmonitor--daemon.h index 2102a5c9ff5..98cbb430083 100644 --- a/fsmonitor--daemon.h +++ b/fsmonitor--daemon.h @@ -8,6 +8,7 @@ #include "run-command.h" #include "simple-ipc.h" #include "thread-utils.h" +#include "fsmonitor-path-utils.h" struct fsmonitor_batch; struct fsmonitor_token_data; @@ -43,6 +44,7 @@ struct fsmonitor_daemon_state { struct strbuf path_worktree_watch; struct strbuf path_gitdir_watch; + struct alias_info alias; int nr_paths_watching; struct fsmonitor_token_data *current_token_data; @@ -59,6 +61,7 @@ struct fsmonitor_daemon_state { struct ipc_server_data *ipc_server_data; struct strbuf path_ipc; + }; /* @@ -167,5 +170,8 @@ void fsmonitor_publish(struct fsmonitor_daemon_state *state, */ void fsmonitor_force_resync(struct fsmonitor_daemon_state *state); +char *fsmonitor_resolve_alias(const char *path, + struct alias_info *alias); + #endif /* HAVE_FSMONITOR_DAEMON_BACKEND */ #endif /* FSMONITOR_DAEMON_H */ diff --git a/fsmonitor-path-utils.h b/fsmonitor-path-utils.h index e48592887e7..7d9d71cb043 100644 --- a/fsmonitor-path-utils.h +++ b/fsmonitor-path-utils.h @@ -1,6 +1,14 @@ #ifndef FSM_PATH_UTILS_H #define FSM_PATH_UTILS_H +#include "strbuf.h" + +struct alias_info +{ + struct strbuf alias; + struct strbuf points_to; +}; + struct fs_info { int is_remote; char *typename; @@ -20,4 +28,22 @@ int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info); */ int fsmonitor__is_fs_remote(const char *path); +/* + * Get the alias in given path, if any. + * + * Sets alias to the first alias that matches any part of the path. + * + * Returns -1 on error, 0 otherwise. + */ +int fsmonitor__get_alias(const char *path, struct alias_info *info); + +/* + * Resolve the path against the given alias. + * + * Returns the resolved path if there is one, NULL otherwise. + */ +char *fsmonitor__resolve_alias(const char *path, + const struct alias_info *info); + + #endif