forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecial_files.go
169 lines (142 loc) · 4.06 KB
/
special_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libfuse
import (
"time"
"bazil.org/fuse/fs"
"github.com/keybase/kbfs/libfs"
"github.com/keybase/kbfs/libkbfs"
)
// handleCommonSpecialFile handles special files that are present both
// within a TLF and outside a TLF.
func handleCommonSpecialFile(
name string, fs *FS, entryValid *time.Duration) fs.Node {
switch name {
case libkbfs.ErrorFile:
return NewErrorFile(fs, entryValid)
case libfs.MetricsFileName:
return NewMetricsFile(fs, entryValid)
case libfs.ProfileListDirName:
return ProfileList{}
case libfs.ResetCachesFileName:
return &ResetCachesFile{fs}
}
return nil
}
// handleNonTLFSpecialFile handles special files that are outside a TLF,
// i.e. /keybase, /keybase/private, and /keybase/public.
func handleNonTLFSpecialFile(
name string, fs *FS, entryValid *time.Duration) fs.Node {
specialNode := handleCommonSpecialFile(name, fs, entryValid)
if specialNode != nil {
return specialNode
}
switch name {
case libfs.StatusFileName:
return NewNonTLFStatusFile(fs, entryValid)
case libfs.HumanErrorFileName, libfs.HumanNoLoginFileName:
*entryValid = 0
return &SpecialReadFile{fs.remoteStatus.NewSpecialReadFunc}
case libfs.EnableAutoJournalsFileName:
return &JournalControlFile{
folder: &Folder{fs: fs}, // fake Folder for logging, etc.
action: libfs.JournalEnableAuto,
}
case libfs.DisableAutoJournalsFileName:
return &JournalControlFile{
folder: &Folder{fs: fs}, // fake Folder for logging, etc.
action: libfs.JournalDisableAuto,
}
case libfs.EnableBlockPrefetchingFileName:
return &PrefetchFile{fs: fs, enable: true}
case libfs.DisableBlockPrefetchingFileName:
return &PrefetchFile{fs: fs, enable: false}
case libfs.EnableDebugServerFileName:
return &DebugServerFile{fs: fs, enable: true}
case libfs.DisableDebugServerFileName:
return &DebugServerFile{fs: fs, enable: false}
}
return nil
}
// handleTLFSpecialFile handles special files that are within a TLF.
func handleTLFSpecialFile(
name string, folder *Folder, entryValid *time.Duration) fs.Node {
specialNode := handleCommonSpecialFile(name, folder.fs, entryValid)
if specialNode != nil {
return specialNode
}
switch name {
case libfs.StatusFileName:
return NewTLFStatusFile(folder, entryValid)
case libfs.UpdateHistoryFileName:
return NewUpdateHistoryFile(folder, entryValid)
case libfs.EditHistoryName:
return NewTlfEditHistoryFile(folder, entryValid)
case libfs.UnstageFileName:
return &UnstageFile{
folder: folder,
}
case libfs.DisableUpdatesFileName:
return &UpdatesFile{
folder: folder,
}
case libfs.EnableUpdatesFileName:
return &UpdatesFile{
folder: folder,
enable: true,
}
case libfs.RekeyFileName:
return &RekeyFile{
folder: folder,
}
case libfs.ReclaimQuotaFileName:
return &ReclaimQuotaFile{
folder: folder,
}
case libfs.SyncFromServerFileName:
// Don't cache the node so that the next lookup of
// this file will force the dir to be re-checked
// (i.e., loadDirHelper will be called again).
*entryValid = 0
return &SyncFromServerFile{
folder: folder,
}
case libfs.EnableJournalFileName:
return &JournalControlFile{
folder: folder,
action: libfs.JournalEnable,
}
case libfs.FlushJournalFileName:
return &JournalControlFile{
folder: folder,
action: libfs.JournalFlush,
}
case libfs.PauseJournalBackgroundWorkFileName:
return &JournalControlFile{
folder: folder,
action: libfs.JournalPauseBackgroundWork,
}
case libfs.ResumeJournalBackgroundWorkFileName:
return &JournalControlFile{
folder: folder,
action: libfs.JournalResumeBackgroundWork,
}
case libfs.DisableJournalFileName:
return &JournalControlFile{
folder: folder,
action: libfs.JournalDisable,
}
case libfs.EnableSyncFileName:
return &SyncControlFile{
folder: folder,
action: libfs.SyncEnable,
}
case libfs.DisableSyncFileName:
return &SyncControlFile{
folder: folder,
action: libfs.SyncDisable,
}
}
return nil
}