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