OLD | NEW |
1 package filetilestore | 1 package filetilestore |
2 | 2 |
3 import ( | 3 import ( |
4 "encoding/gob" | 4 "encoding/gob" |
5 "fmt" | 5 "fmt" |
6 "io/ioutil" | 6 "io/ioutil" |
7 "os" | 7 "os" |
8 "path" | 8 "path" |
9 "path/filepath" | 9 "path/filepath" |
10 "sort" | 10 "sort" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 // Cache for recently used tiles. | 53 // Cache for recently used tiles. |
54 cache *lru.Cache | 54 cache *lru.Cache |
55 | 55 |
56 // Mutex for ensuring safe access to the cache and lastTile. | 56 // Mutex for ensuring safe access to the cache and lastTile. |
57 lock sync.Mutex | 57 lock sync.Mutex |
58 } | 58 } |
59 | 59 |
60 // tileFilename creates the filename for the given tile scale and index for the | 60 // tileFilename creates the filename for the given tile scale and index for the |
61 // given FileTileStore. | 61 // given FileTileStore. |
62 func (store FileTileStore) tileFilename(scale, index int) (string, error) { | 62 func (store *FileTileStore) tileFilename(scale, index int) (string, error) { |
63 if scale < 0 || index < 0 { | 63 if scale < 0 || index < 0 { |
64 return "", fmt.Errorf("Scale %d and Index %d must both be >= 0",
scale, index) | 64 return "", fmt.Errorf("Scale %d and Index %d must both be >= 0",
scale, index) |
65 } | 65 } |
66 return path.Join(store.dir, store.datasetName, fmt.Sprintf("%d/%04d.gob"
, scale, index)), nil | 66 return path.Join(store.dir, store.datasetName, fmt.Sprintf("%d/%04d.gob"
, scale, index)), nil |
67 } | 67 } |
68 | 68 |
69 // fileTileTemp creates a unique temporary filename for the given tile scale and | 69 // fileTileTemp creates a unique temporary filename for the given tile scale and |
70 // index for the given FileTileStore. Used during Put() so that writes update | 70 // index for the given FileTileStore. Used during Put() so that writes update |
71 // atomically. | 71 // atomically. |
72 func (store FileTileStore) fileTileTemp(scale, index int) (*os.File, error) { | 72 func (store *FileTileStore) fileTileTemp(scale, index int) (*os.File, error) { |
73 if scale < 0 || index < 0 { | 73 if scale < 0 || index < 0 { |
74 return nil, fmt.Errorf("Scale %d and Index %d must both be >= 0"
, scale, index) | 74 return nil, fmt.Errorf("Scale %d and Index %d must both be >= 0"
, scale, index) |
75 } | 75 } |
76 dir := path.Join(store.dir, TEMP_TILE_DIR_NAME) | 76 dir := path.Join(store.dir, TEMP_TILE_DIR_NAME) |
77 if err := os.MkdirAll(dir, 0755); err != nil { | 77 if err := os.MkdirAll(dir, 0755); err != nil { |
78 return nil, fmt.Errorf("Error creating directory for temp tile %
s: %s", dir, err) | 78 return nil, fmt.Errorf("Error creating directory for temp tile %
s: %s", dir, err) |
79 } | 79 } |
80 return ioutil.TempFile(dir, fmt.Sprintf("%d-%04d-gob-", scale, index)) | 80 return ioutil.TempFile(dir, fmt.Sprintf("%d-%04d-gob-", scale, index)) |
81 } | 81 } |
82 | 82 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 // Refresh the lastTile entries periodically. | 329 // Refresh the lastTile entries periodically. |
330 go func() { | 330 go func() { |
331 for _ = range time.Tick(checkEvery) { | 331 for _ = range time.Tick(checkEvery) { |
332 store.refreshLastTiles() | 332 store.refreshLastTiles() |
333 } | 333 } |
334 }() | 334 }() |
335 } | 335 } |
336 return store | 336 return store |
337 } | 337 } |
OLD | NEW |