Skip to content

Instantly share code, notes, and snippets.

@splhack
Last active April 14, 2017 23:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splhack/86c81f903449f7529b32 to your computer and use it in GitHub Desktop.
Save splhack/86c81f903449f7529b32 to your computer and use it in GitHub Desktop.
Unity with unionfs on OS X
diff --git a/src/Makefile b/src/Makefile
index 82f7a1c..dfcbc95 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,11 +1,15 @@
-CFLAGS += -Wall
-CPPFLAGS += $(shell pkg-config --cflags fuse)
+CFLAGS += -Wall -mmacosx-version-min=10.6 $(ARCH)
+#CPPFLAGS += $(shell pkg-config --cflags fuse)
+CPPFLAGS += -I/usr/local/include/osxfuse
CPPFLAGS += -DFUSE_USE_VERSION=26
-CPPFLAGS += -DHAVE_XATTR
+#CPPFLAGS += -DHAVE_XATTR
+#CPPFLAGS += -DHAVE_MALLOC_H
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
-LDFLAGS +=
+LDFLAGS += -mmacosx-version-min=10.6 $(ARCH)
-LIB = $(shell pkg-config --libs fuse)
+#LIB = $(shell pkg-config --libs fuse)
+LIB = -L/usr/local/lib $(OSXFUSE_ARCH_LIB)
HASHTABLE_OBJ = hashtable.o hashtable_itr.o
UNIONFS_OBJ = unionfs.o stats.o opts.o debug.o findbranch.o readdir.o \
diff --git a/src/unionfs.c b/src/unionfs.c
index 186cd53..c1b79fd 100644
--- a/src/unionfs.c
+++ b/src/unionfs.c
@@ -190,7 +190,7 @@ static int unionfs_getattr(const char *path, struct stat *stbuf) {
DBG("%s\n", path);
if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) {
- memset(stbuf, 0, sizeof(stbuf));
+ memset(stbuf, 0, sizeof(*stbuf));
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
stbuf->st_size = STATS_SIZE;
@@ -663,7 +663,27 @@ static int unionfs_utimens(const char *path, const struct timespec ts[2]) {
char p[PATHLEN_MAX];
if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG);
- int res = utimensat(0, p, ts, AT_SYMLINK_NOFOLLOW);
+
+ int res;
+#ifdef HAVE_UTIMENSAT
+ res = utimensat(0, p, ts, AT_SYMLINK_NOFOLLOW);
+#else
+ struct timeval tv_copy[2];
+ struct timeval *tv;
+ if (ts != NULL)
+ {
+ tv_copy[0].tv_sec = ts[0].tv_sec;
+ tv_copy[0].tv_usec = ts[0].tv_nsec / 1000;
+ tv_copy[1].tv_sec = ts[1].tv_sec;
+ tv_copy[1].tv_usec = ts[1].tv_nsec / 1000;
+ tv = tv_copy;
+ }
+ else
+ {
+ tv = NULL;
+ }
+ res = utimes(p, tv);
+#endif
if (res == -1) RETURN(-errno);
diff --git a/src/usyslog.c b/src/usyslog.c
index 75becac..0c8a8ed 100644
--- a/src/usyslog.c
+++ b/src/usyslog.c
@@ -20,7 +20,9 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#ifdef HAVE_MALLOC_H
#include <malloc.h>
+#endif
#include <pthread.h>
#include <stdarg.h>

ビルド

$ OSXFUSE_ARCH_LIB=-losxfuse make

元になるUnityプロジェクト ORIGINAL、ターゲットを切り替えて新しくUnityを起動したいプロジェクト NEW とすると

$ mkdir -r NEW/Assets
$ mkdir -r NEW/Assets.rw
$ unionfs -o cow -o allow_other NEW/Assets.rw=RW:ORIGINAL/Assets=RO NEW/Assets

で、ORIGINALとNEWのディレクトリで別々に、Unity起動すればOK

$ /Applications/Unity/Unity.app/Contents/MacOS/Unity -projectPath ORIGINAL &!
$ /Applications/Unity/Unity.app/Contents/MacOS/Unity -projectPath NEW &!

ORIGINALの方でファイルを更新すると、NEWの方でも遅延なくそのまま反映される。 NEWの方でファイルを更新と、copy on writeで、NEW/Assets.rwに書き換えたファイルが保存されて、ORIGINAL/Assetsは元のまま残る。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment