func deleteUnneededFiles(srpcClient *srpc.Client, subFS *filesystem.FileSystem, imgFS *filesystem.FileSystem, logger *log.Logger) bool { startTime := showStart("compute early files to delete") pathsToDelete := make([]string, 0) imgHashToInodesTable := imgFS.HashToInodesTable() imgFilenameToInodeTable := imgFS.FilenameToInodeTable() for pathname, inum := range subFS.FilenameToInodeTable() { if inode, ok := subFS.InodeTable[inum].(*filesystem.RegularInode); ok { if inode.Size > 0 { if _, ok := imgHashToInodesTable[inode.Hash]; !ok { pathsToDelete = append(pathsToDelete, pathname) } } else { if _, ok := imgFilenameToInodeTable[pathname]; !ok { pathsToDelete = append(pathsToDelete, pathname) } } } } showTimeTaken(startTime) if len(pathsToDelete) < 1 { return false } updateRequest := sub.UpdateRequest{ Wait: true, PathsToDelete: pathsToDelete} var updateReply sub.UpdateResponse startTime = showStart("Subd.Update() for early files to delete") err := client.CallUpdate(srpcClient, updateRequest, &updateReply) showTimeTaken(startTime) if err != nil { logger.Println(err) } return true }
func copyMissingObjects(fs *filesystem.FileSystem, imageSClient *srpc.Client, objectClient *objectclient.ObjectClient, subName string) error { // Check to see which objects are in the objectserver. hashes := make([]hash.Hash, 0, fs.NumRegularInodes) for hash, _ := range fs.HashToInodesTable() { hashes = append(hashes, hash) } objectSizes, err := objectClient.CheckObjects(hashes) if err != nil { return err } missingHashes := make([]hash.Hash, 0) for index, size := range objectSizes { if size < 1 { missingHashes = append(missingHashes, hashes[index]) } } if len(missingHashes) < 1 { return nil } // Get missing objects from sub. filesForMissingObjects := make([]string, 0, len(missingHashes)) for _, hash := range missingHashes { if inums, ok := fs.HashToInodesTable()[hash]; !ok { return fmt.Errorf("no inode for object: %x", hash) } else if files, ok := fs.InodeToFilenamesTable()[inums[0]]; !ok { return fmt.Errorf("no file for inode: %d", inums[0]) } else { filesForMissingObjects = append(filesForMissingObjects, files[0]) } } objAdderQueue, err := objectclient.NewObjectAdderQueue(imageSClient) if err != nil { return err } subClient, err := srpc.DialHTTP("tcp", fmt.Sprintf("%s:%d", subName, constants.SubPortNumber), 0) if err != nil { return fmt.Errorf("error dialing %s", err) } defer subClient.Close() if err := subclient.GetFiles(subClient, filesForMissingObjects, func(reader io.Reader, size uint64) error { _, err := objAdderQueue.Add(reader, size) return err }); err != nil { return err } return objAdderQueue.Close() }