Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: go/src/infra/tools/cipd/local/deployer.go

Issue 1358533003: cipd: Implement 'init', 'install' and 'installed' subcommands. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/local/manifest.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package local 5 package local
6 6
7 import ( 7 import (
8 "crypto/sha1" 8 "crypto/sha1"
9 "encoding/base64" 9 "encoding/base64"
10 "fmt" 10 "fmt"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 func (d errDeployer) DeployInstance(PackageInstance) (common.Pin, error) { ret urn common.Pin{}, d.err } 98 func (d errDeployer) DeployInstance(PackageInstance) (common.Pin, error) { ret urn common.Pin{}, d.err }
99 func (d errDeployer) CheckDeployed(packageName string) (common.Pin, error) { ret urn common.Pin{}, d.err } 99 func (d errDeployer) CheckDeployed(packageName string) (common.Pin, error) { ret urn common.Pin{}, d.err }
100 func (d errDeployer) FindDeployed() (out []common.Pin, err error) { ret urn nil, d.err } 100 func (d errDeployer) FindDeployed() (out []common.Pin, err error) { ret urn nil, d.err }
101 func (d errDeployer) RemoveDeployed(packageName string) error { ret urn d.err } 101 func (d errDeployer) RemoveDeployed(packageName string) error { ret urn d.err }
102 func (d errDeployer) TempFile(prefix string) (*os.File, error) { ret urn nil, d.err } 102 func (d errDeployer) TempFile(prefix string) (*os.File, error) { ret urn nil, d.err }
103 103
104 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
105 // Real deployer implementation. 105 // Real deployer implementation.
106 106
107 // packagesDir is a subdirectory of site root to extract packages to. 107 // packagesDir is a subdirectory of site root to extract packages to.
108 const packagesDir = siteServiceDir + "/pkgs" 108 const packagesDir = SiteServiceDir + "/pkgs"
109 109
110 // currentSymlink is a name of a symlink that points to latest deployed version. 110 // currentSymlink is a name of a symlink that points to latest deployed version.
111 // Used on Linux and Mac. 111 // Used on Linux and Mac.
112 const currentSymlink = "_current" 112 const currentSymlink = "_current"
113 113
114 // currentTxt is a name of a text file with instance ID of latest deployed 114 // currentTxt is a name of a text file with instance ID of latest deployed
115 // version. Used on Windows. 115 // version. Used on Windows.
116 const currentTxt = "_current.txt" 116 const currentTxt = "_current.txt"
117 117
118 // deployerImpl implements Deployer interface. 118 // deployerImpl implements Deployer interface.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // will nuke everything (even if it's half broken). 299 // will nuke everything (even if it's half broken).
300 if err != nil { 300 if err != nil {
301 d.logger.Warningf("Package %s is in a broken state: %s", package Name, err) 301 d.logger.Warningf("Package %s is in a broken state: %s", package Name, err)
302 } else { 302 } else {
303 d.removeFromSiteRoot(manifest.Files) 303 d.removeFromSiteRoot(manifest.Files)
304 } 304 }
305 return d.fs.EnsureDirectoryGone(pkgPath) 305 return d.fs.EnsureDirectoryGone(pkgPath)
306 } 306 }
307 307
308 func (d *deployerImpl) TempFile(prefix string) (*os.File, error) { 308 func (d *deployerImpl) TempFile(prefix string) (*os.File, error) {
309 » dir, err := d.fs.EnsureDirectory(filepath.Join(d.fs.Root(), siteServiceD ir, "tmp")) 309 » dir, err := d.fs.EnsureDirectory(filepath.Join(d.fs.Root(), SiteServiceD ir, "tmp"))
310 if err != nil { 310 if err != nil {
311 return nil, err 311 return nil, err
312 } 312 }
313 return ioutil.TempFile(dir, prefix) 313 return ioutil.TempFile(dir, prefix)
314 } 314 }
315 315
316 //////////////////////////////////////////////////////////////////////////////// 316 ////////////////////////////////////////////////////////////////////////////////
317 // Utility methods. 317 // Utility methods.
318 318
319 // packagePath returns a path to a package directory in .cipd/pkgs/. 319 // packagePath returns a path to a package directory in .cipd/pkgs/.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 func scanPackageDir(dir string, l logging.Logger) ([]FileInfo, error) { 511 func scanPackageDir(dir string, l logging.Logger) ([]FileInfo, error) {
512 out := []FileInfo{} 512 out := []FileInfo{}
513 err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { 513 err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
514 if err != nil { 514 if err != nil {
515 return err 515 return err
516 } 516 }
517 rel, err := filepath.Rel(dir, path) 517 rel, err := filepath.Rel(dir, path)
518 if err != nil { 518 if err != nil {
519 return err 519 return err
520 } 520 }
521 » » if rel == packageServiceDir || rel == siteServiceDir { 521 » » if rel == packageServiceDir || rel == SiteServiceDir {
522 return filepath.SkipDir 522 return filepath.SkipDir
523 } 523 }
524 if info.Mode().IsRegular() || info.Mode()&os.ModeSymlink != 0 { 524 if info.Mode().IsRegular() || info.Mode()&os.ModeSymlink != 0 {
525 symlink := "" 525 symlink := ""
526 ok := true 526 ok := true
527 if info.Mode()&os.ModeSymlink != 0 { 527 if info.Mode()&os.ModeSymlink != 0 {
528 symlink, err = os.Readlink(path) 528 symlink, err = os.Readlink(path)
529 if err != nil { 529 if err != nil {
530 l.Warningf("Can't readlink %q, skipping: %s", path, err) 530 l.Warningf("Can't readlink %q, skipping: %s", path, err)
531 ok = false 531 ok = false
532 } 532 }
533 } 533 }
534 if ok { 534 if ok {
535 out = append(out, FileInfo{ 535 out = append(out, FileInfo{
536 Name: filepath.ToSlash(rel), 536 Name: filepath.ToSlash(rel),
537 Size: uint64(info.Size()), 537 Size: uint64(info.Size()),
538 Executable: (info.Mode().Perm() & 0111) != 0, 538 Executable: (info.Mode().Perm() & 0111) != 0,
539 Symlink: symlink, 539 Symlink: symlink,
540 }) 540 })
541 } 541 }
542 } 542 }
543 return nil 543 return nil
544 }) 544 })
545 return out, err 545 return out, err
546 } 546 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/local/manifest.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698