(driver *Strm, localPath string, objs []model.Obj)
| 172 | } |
| 173 | |
| 174 | func deleteExtraFiles(driver *Strm, localPath string, objs []model.Obj) { |
| 175 | if driver.SaveLocalMode != SaveLocalSyncMode { |
| 176 | return |
| 177 | } |
| 178 | localFiles, localDirs, err := getLocalDirsAndFiles(localPath) |
| 179 | if err != nil { |
| 180 | log.Errorf("Failed to read local files from %s: %v", localPath, err) |
| 181 | return |
| 182 | } |
| 183 | |
| 184 | fileSet := make(map[string]struct{}) |
| 185 | dirSet := make(map[string]struct{}) |
| 186 | for _, obj := range objs { |
| 187 | objPath := stdpath.Join(localPath, obj.GetName()) |
| 188 | if obj.IsDir() { |
| 189 | dirSet[objPath] = struct{}{} |
| 190 | } else { |
| 191 | fileSet[objPath] = struct{}{} |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | for _, localFile := range localFiles { |
| 196 | if _, exists := fileSet[localFile]; !exists { |
| 197 | err := os.Remove(localFile) |
| 198 | if err != nil { |
| 199 | log.Errorf("Failed to delete file: %s, error: %v\n", localFile, err) |
| 200 | } else { |
| 201 | log.Infof("Deleted file %s", localFile) |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | for _, localDir := range localDirs { |
| 207 | if _, exists := dirSet[localDir]; !exists { |
| 208 | err := os.RemoveAll(localDir) |
| 209 | if err != nil { |
| 210 | log.Errorf("Failed to delete directory: %s, error: %v\n", localDir, err) |
| 211 | } else { |
| 212 | log.Infof("Deleted directory %s", localDir) |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | func getLocalDirsAndFiles(localPath string) ([]string, []string, error) { |
| 219 | var files, dirs []string |
no test coverage detected