blob: 082fc255ce7d7345eb9e9176b1726299020e70ed [file] [log] [blame]
Bogdan Caprita78b62162014-08-21 15:35:08 -07001package impl
2
Bogdan Caprita9d285a12014-09-30 15:04:16 -07003import (
Robert Kroeger362ff892014-09-29 14:23:47 -07004 "flag"
Bogdan Caprita9d285a12014-09-30 15:04:16 -07005 "os"
6 "path/filepath"
7
Bogdan Caprita54ae80e2015-01-20 13:37:52 -08008 "v.io/core/veyron2/services/mgmt/device"
Jiri Simsa764efb72014-12-25 20:57:03 -08009 "v.io/core/veyron2/vlog"
Bogdan Caprita9d285a12014-09-30 15:04:16 -070010)
11
Bogdan Caprita78b62162014-08-21 15:35:08 -070012// This file contains code in the impl package that we only want built for tests
13// (it exposes public API methods that we don't want to normally expose).
14
Robert Kroeger362ff892014-09-29 14:23:47 -070015var mockIsSetuid = flag.Bool("mocksetuid", false, "set flag to pretend to have a helper with setuid permissions")
16
Bogdan Caprita78b62162014-08-21 15:35:08 -070017func (c *callbackState) leaking() bool {
18 c.Lock()
19 defer c.Unlock()
20 return len(c.channels) > 0
21}
22
23func (d *dispatcher) Leaking() bool {
24 return d.internal.callback.leaking()
25}
Bogdan Caprita9d285a12014-09-30 15:04:16 -070026
27func init() {
Robert Kroeger94ec7562014-10-28 17:58:44 -070028 cleanupDir = func(dir, helper string) {
Bogdan Capritac2777ee2014-11-18 23:00:02 -080029 if dir == "" {
30 return
31 }
Bogdan Caprita9d285a12014-09-30 15:04:16 -070032 parentDir, base := filepath.Dir(dir), filepath.Base(dir)
Robert Kroeger94ec7562014-10-28 17:58:44 -070033 var renamed string
34 if helper != "" {
35 renamed = filepath.Join(parentDir, "helper_deleted_"+base)
36 } else {
37 renamed = filepath.Join(parentDir, "deleted_"+base)
38 }
Bogdan Caprita9d285a12014-09-30 15:04:16 -070039 if err := os.Rename(dir, renamed); err != nil {
40 vlog.Errorf("Rename(%v, %v) failed: %v", dir, renamed, err)
41 }
42 }
Robert Kroeger362ff892014-09-29 14:23:47 -070043 isSetuid = possiblyMockIsSetuid
Bogdan Caprita54ae80e2015-01-20 13:37:52 -080044
Robin Thellend753de652015-01-26 13:50:56 -080045 Describe = func() (descr device.Description, err error) {
Bogdan Caprita54ae80e2015-01-20 13:37:52 -080046 return device.Description{Profiles: map[string]struct{}{"test-profile": struct{}{}}}, nil
47 }
Robert Kroeger362ff892014-09-29 14:23:47 -070048}
49
50func possiblyMockIsSetuid(fileStat os.FileInfo) bool {
51 vlog.VI(2).Infof("Mock isSetuid is reporting: %v", *mockIsSetuid)
52 return *mockIsSetuid
Bogdan Caprita9d285a12014-09-30 15:04:16 -070053}
Robert Kroeger94ec7562014-10-28 17:58:44 -070054
55func WrapBaseCleanupDir(path, helper string) {
56 baseCleanupDir(path, helper)
57}