@@ -7,20 +7,17 @@ namespace GitHub.Unity
7
7
{
8
8
class LfsLocksModificationProcessor : UnityEditor . AssetModificationProcessor
9
9
{
10
- private static ILogging logger ;
11
- private static ILogging Logger { get { return logger = logger ?? LogHelper . GetLogger < LfsLocksModificationProcessor > ( ) ; } }
12
-
10
+ private static ILogging Logger = LogHelper . GetLogger < LfsLocksModificationProcessor > ( ) ;
13
11
private static IRepository repository ;
14
-
12
+ private static IPlatform platform ;
15
13
private static List < GitLock > locks = new List < GitLock > ( ) ;
16
-
17
14
private static CacheUpdateEvent lastLocksChangedEvent ;
18
15
19
- public static void Initialize ( IRepository repo )
16
+ public static void Initialize ( IRepository repo , IPlatform plat )
20
17
{
21
- Logger . Trace ( "Initialize HasRepository:{0}" , repo != null ) ;
22
-
18
+ //Logger.Trace("Initialize HasRepository:{0}", repo != null);
23
19
repository = repo ;
20
+ platform = plat ;
24
21
25
22
if ( repository != null )
26
23
{
@@ -29,24 +26,15 @@ public static void Initialize(IRepository repo)
29
26
}
30
27
}
31
28
32
- private static void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
33
- {
34
- if ( ! lastLocksChangedEvent . Equals ( cacheUpdateEvent ) )
35
- {
36
- lastLocksChangedEvent = cacheUpdateEvent ;
37
- locks = repository . CurrentLocks ;
38
- }
39
- }
40
-
41
29
public static string [ ] OnWillSaveAssets ( string [ ] paths )
42
30
{
43
- Logger . Trace ( "OnWillSaveAssets: [{0}]" , string . Join ( ", " , paths ) ) ;
31
+ // Logger.Trace("OnWillSaveAssets: [{0}]", string.Join(", ", paths));
44
32
return paths ;
45
33
}
46
34
47
35
public static AssetMoveResult OnWillMoveAsset ( string oldPath , string newPath )
48
36
{
49
- Logger . Trace ( "OnWillMoveAsset:{0}->{1}" , oldPath , newPath ) ;
37
+ // Logger.Trace("OnWillMoveAsset:{0}->{1}", oldPath, newPath);
50
38
51
39
var result = AssetMoveResult . DidNotMove ;
52
40
if ( IsLocked ( oldPath ) )
@@ -62,22 +50,17 @@ public static AssetMoveResult OnWillMoveAsset(string oldPath, string newPath)
62
50
63
51
public static AssetDeleteResult OnWillDeleteAsset ( string assetPath , RemoveAssetOptions option )
64
52
{
65
- Logger . Trace ( "OnWillDeleteAsset:{0}" , assetPath ) ;
66
-
67
- if ( IsLocked ( assetPath ) )
68
- {
69
- return AssetDeleteResult . FailedDelete ;
70
- }
71
- return AssetDeleteResult . DidNotDelete ;
53
+ //Logger.Trace("OnWillDeleteAsset:{0}", assetPath);
54
+ return IsLocked ( assetPath ) ? AssetDeleteResult . FailedDelete : AssetDeleteResult . DidNotDelete ;
72
55
}
73
56
74
57
public static bool IsOpenForEdit ( string assetPath , out string message )
75
58
{
76
- Logger . Trace ( "IsOpenForEdit:{0}" , assetPath ) ;
77
-
78
- if ( IsLocked ( assetPath ) )
59
+ // Logger.Trace("IsOpenForEdit:{0}", assetPath);
60
+ var lck = GetLock ( assetPath ) ;
61
+ if ( lck . HasValue )
79
62
{
80
- message = "File is locked for editing!" ;
63
+ message = "File is locked for editing by " + lck . Value . User ;
81
64
return false ;
82
65
}
83
66
else
@@ -87,21 +70,38 @@ public static bool IsOpenForEdit(string assetPath, out string message)
87
70
}
88
71
}
89
72
73
+ private static void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
74
+ {
75
+ if ( ! lastLocksChangedEvent . Equals ( cacheUpdateEvent ) )
76
+ {
77
+ lastLocksChangedEvent = cacheUpdateEvent ;
78
+ locks = repository . CurrentLocks ;
79
+ }
80
+ }
81
+
90
82
private static bool IsLocked ( string assetPath )
91
83
{
92
- if ( repository != null )
93
- {
84
+ return GetLock ( assetPath ) . HasValue ;
85
+ }
86
+
87
+ private static GitLock ? GetLock ( string assetPath )
88
+ {
89
+ GitLock ? gitLock = null ;
90
+ if ( repository != null )
91
+ {
94
92
var repositoryPath = EntryPoint . Environment . GetRepositoryPath ( assetPath . ToNPath ( ) ) ;
95
- var gitLock = locks . FirstOrDefault ( @lock => @lock . Path == repositoryPath ) ;
96
- if ( ! gitLock . Equals ( GitLock . Default ) )
93
+ var lck = locks . FirstOrDefault ( @lock => @lock . Path == repositoryPath ) ;
94
+ if ( ! lck . Equals ( GitLock . Default ) )
97
95
{
98
- Logger . Trace ( "Lock found on: {0}" , assetPath ) ;
99
-
100
- //TODO: Check user and return true
96
+ var user = platform . Keychain . Connections . FirstOrDefault ( ) ;
97
+ if ( ! lck . User . Equals ( user ) )
98
+ {
99
+ gitLock = lck ;
100
+ }
101
+ //Logger.Trace("Lock found on: {0}", assetPath);
101
102
}
102
103
}
103
-
104
- return false ;
104
+ return gitLock ;
105
105
}
106
106
}
107
- }
107
+ }
0 commit comments