OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package local |
| 6 |
| 7 import ( |
| 8 "encoding/json" |
| 9 "io" |
| 10 "io/ioutil" |
| 11 ) |
| 12 |
| 13 // Name of the directory inside an installation root reserved for cipd stuff. |
| 14 const SiteServiceDir = ".cipd" |
| 15 |
| 16 // Name of the directory inside the package reserved for cipd stuff. |
| 17 const packageServiceDir = ".cipdpkg" |
| 18 |
| 19 // Name of the manifest file inside the package. |
| 20 const manifestName = packageServiceDir + "/manifest.json" |
| 21 |
| 22 // Format version to write to the manifest file. |
| 23 const manifestFormatVersion = "1" |
| 24 |
| 25 // Manifest defines structure of manifest.json file. |
| 26 type Manifest struct { |
| 27 FormatVersion string `json:"format_version"` |
| 28 PackageName string `json:"package_name"` |
| 29 } |
| 30 |
| 31 // readManifest reads and decodes manifest JSON from io.Reader. |
| 32 func readManifest(r io.Reader) (manifest Manifest, err error) { |
| 33 blob, err := ioutil.ReadAll(r) |
| 34 if err == nil { |
| 35 err = json.Unmarshal(blob, &manifest) |
| 36 } |
| 37 return |
| 38 } |
| 39 |
| 40 // writeManifest encodes and writes manifest JSON to io.Writer. |
| 41 func writeManifest(m *Manifest, w io.Writer) error { |
| 42 data, err := json.MarshalIndent(m, "", " ") |
| 43 if err != nil { |
| 44 return err |
| 45 } |
| 46 _, err = w.Write(data) |
| 47 return err |
| 48 } |
OLD | NEW |