| 55 | } |
| 56 | |
| 57 | func newSharedPullerState(file protocol.FileInfo, fs fs.Filesystem, folderID, tempName string, blocks []protocol.BlockInfo, reused []int, ignorePerms, hasCurFile bool, curFile protocol.FileInfo, sparse bool, fsync bool) *sharedPullerState { |
| 58 | // Map the existing blocks by hash to block index in the current file |
| 59 | blocksMap := make(map[string]int, len(curFile.Blocks)) |
| 60 | for idx, block := range curFile.Blocks { |
| 61 | blocksMap[string(block.Hash)] = idx |
| 62 | } |
| 63 | |
| 64 | return &sharedPullerState{ |
| 65 | file: file, |
| 66 | fs: fs, |
| 67 | folder: folderID, |
| 68 | tempName: tempName, |
| 69 | realName: file.Name, |
| 70 | copyTotal: len(blocks), |
| 71 | copyNeeded: len(blocks), |
| 72 | reused: len(reused), |
| 73 | updated: time.Now(), |
| 74 | available: reused, |
| 75 | availableUpdated: time.Now(), |
| 76 | ignorePerms: ignorePerms, |
| 77 | hasCurFile: hasCurFile, |
| 78 | curFile: curFile, |
| 79 | curFileBlocks: blocksMap, |
| 80 | sparse: sparse, |
| 81 | fsync: fsync, |
| 82 | created: time.Now(), |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // A momentary state representing the progress of the puller |
| 87 | type PullerProgress struct { |