sandbox.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. package libnetwork
  2. import (
  3. "container/heap"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "path"
  9. "path/filepath"
  10. "sync"
  11. log "github.com/Sirupsen/logrus"
  12. "github.com/docker/libnetwork/etchosts"
  13. "github.com/docker/libnetwork/osl"
  14. "github.com/docker/libnetwork/resolvconf"
  15. "github.com/docker/libnetwork/types"
  16. )
  17. // Sandbox provides the control over the network container entity. It is a one to one mapping with the container.
  18. type Sandbox interface {
  19. // ID returns the ID of the sandbox
  20. ID() string
  21. // Key returns the sandbox's key
  22. Key() string
  23. // ContainerID returns the container id associated to this sandbox
  24. ContainerID() string
  25. // Labels returns the sandbox's labels
  26. Labels() map[string]interface{}
  27. // Statistics retrieves the interfaces' statistics for the sandbox
  28. Statistics() (map[string]*osl.InterfaceStatistics, error)
  29. // Delete destroys this container after detaching it from all connected endpoints.
  30. Delete() error
  31. }
  32. // SandboxOption is a option setter function type used to pass varios options to
  33. // NewNetContainer method. The various setter functions of type SandboxOption are
  34. // provided by libnetwork, they look like ContainerOptionXXXX(...)
  35. type SandboxOption func(sb *sandbox)
  36. func (sb *sandbox) processOptions(options ...SandboxOption) {
  37. for _, opt := range options {
  38. if opt != nil {
  39. opt(sb)
  40. }
  41. }
  42. }
  43. type epHeap []*endpoint
  44. type sandbox struct {
  45. id string
  46. containerID string
  47. config containerConfig
  48. osSbox osl.Sandbox
  49. controller *controller
  50. refCnt int
  51. endpoints epHeap
  52. epPriority map[string]int
  53. //hostsPath string
  54. //resolvConfPath string
  55. joinLeaveDone chan struct{}
  56. sync.Mutex
  57. }
  58. // These are the container configs used to customize container /etc/hosts file.
  59. type hostsPathConfig struct {
  60. hostName string
  61. domainName string
  62. hostsPath string
  63. originHostsPath string
  64. extraHosts []extraHost
  65. parentUpdates []parentUpdate
  66. }
  67. type parentUpdate struct {
  68. cid string
  69. name string
  70. ip string
  71. }
  72. type extraHost struct {
  73. name string
  74. IP string
  75. }
  76. // These are the container configs used to customize container /etc/resolv.conf file.
  77. type resolvConfPathConfig struct {
  78. resolvConfPath string
  79. originResolvConfPath string
  80. resolvConfHashFile string
  81. dnsList []string
  82. dnsSearchList []string
  83. dnsOptionsList []string
  84. }
  85. type containerConfig struct {
  86. hostsPathConfig
  87. resolvConfPathConfig
  88. generic map[string]interface{}
  89. useDefaultSandBox bool
  90. prio int // higher the value, more the priority
  91. }
  92. func (sb *sandbox) ID() string {
  93. return sb.id
  94. }
  95. func (sb *sandbox) ContainerID() string {
  96. return sb.containerID
  97. }
  98. func (sb *sandbox) Key() string {
  99. if sb.config.useDefaultSandBox {
  100. return osl.GenerateKey("default")
  101. }
  102. return osl.GenerateKey(sb.id)
  103. }
  104. func (sb *sandbox) Labels() map[string]interface{} {
  105. return sb.config.generic
  106. }
  107. func (sb *sandbox) Statistics() (map[string]*osl.InterfaceStatistics, error) {
  108. m := make(map[string]*osl.InterfaceStatistics)
  109. if sb.osSbox == nil {
  110. return m, nil
  111. }
  112. var err error
  113. for _, i := range sb.osSbox.Info().Interfaces() {
  114. if m[i.DstName()], err = i.Statistics(); err != nil {
  115. return m, err
  116. }
  117. }
  118. return m, nil
  119. }
  120. func (sb *sandbox) Delete() error {
  121. sb.Lock()
  122. c := sb.controller
  123. eps := make([]*endpoint, len(sb.endpoints))
  124. for i, ep := range sb.endpoints {
  125. eps[i] = ep
  126. }
  127. sb.Unlock()
  128. // Detach from all containers
  129. for _, ep := range eps {
  130. if err := ep.Leave(sb); err != nil {
  131. log.Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err)
  132. }
  133. }
  134. if sb.osSbox != nil {
  135. sb.osSbox.Destroy()
  136. }
  137. c.Lock()
  138. delete(c.sandboxes, sb.ID())
  139. c.Unlock()
  140. return nil
  141. }
  142. func (sb *sandbox) MarshalJSON() ([]byte, error) {
  143. sb.Lock()
  144. defer sb.Unlock()
  145. // We are just interested in the container ID. This can be expanded to include all of containerInfo if there is a need
  146. return json.Marshal(sb.id)
  147. }
  148. func (sb *sandbox) UnmarshalJSON(b []byte) (err error) {
  149. sb.Lock()
  150. defer sb.Unlock()
  151. var id string
  152. if err := json.Unmarshal(b, &id); err != nil {
  153. return err
  154. }
  155. sb.id = id
  156. return nil
  157. }
  158. func (sb *sandbox) updateGateway(ep *endpoint) error {
  159. sb.osSbox.UnsetGateway()
  160. sb.osSbox.UnsetGatewayIPv6()
  161. if ep == nil {
  162. return nil
  163. }
  164. ep.Lock()
  165. joinInfo := ep.joinInfo
  166. ep.Unlock()
  167. if err := sb.osSbox.SetGateway(joinInfo.gw); err != nil {
  168. return fmt.Errorf("failed to set gateway while updating gateway: %v", err)
  169. }
  170. if err := sb.osSbox.SetGatewayIPv6(joinInfo.gw6); err != nil {
  171. return fmt.Errorf("failed to set IPv6 gateway while updating gateway: %v", err)
  172. }
  173. return nil
  174. }
  175. func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
  176. ep.Lock()
  177. joinInfo := ep.joinInfo
  178. ifaces := ep.iFaces
  179. ep.Unlock()
  180. for _, i := range ifaces {
  181. var ifaceOptions []osl.IfaceOption
  182. ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().Address(&i.addr), sb.osSbox.InterfaceOptions().Routes(i.routes))
  183. if i.addrv6.IP.To16() != nil {
  184. ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().AddressIPv6(&i.addrv6))
  185. }
  186. if err := sb.osSbox.AddInterface(i.srcName, i.dstPrefix, ifaceOptions...); err != nil {
  187. return fmt.Errorf("failed to add interface %s to sandbox: %v", i.srcName, err)
  188. }
  189. }
  190. if joinInfo != nil {
  191. // Set up non-interface routes.
  192. for _, r := range joinInfo.StaticRoutes {
  193. if err := sb.osSbox.AddStaticRoute(r); err != nil {
  194. return fmt.Errorf("failed to add static route %s: %v", r.Destination.String(), err)
  195. }
  196. }
  197. }
  198. sb.Lock()
  199. heap.Push(&sb.endpoints, ep)
  200. highEp := sb.endpoints[0]
  201. sb.Unlock()
  202. if ep == highEp {
  203. if err := sb.updateGateway(ep); err != nil {
  204. return err
  205. }
  206. }
  207. return nil
  208. }
  209. func (sb *sandbox) clearNetworkResources(ep *endpoint) error {
  210. for _, i := range sb.osSbox.Info().Interfaces() {
  211. // Only remove the interfaces owned by this endpoint from the sandbox.
  212. if ep.hasInterface(i.SrcName()) {
  213. if err := i.Remove(); err != nil {
  214. log.Debugf("Remove interface failed: %v", err)
  215. }
  216. }
  217. }
  218. ep.Lock()
  219. joinInfo := ep.joinInfo
  220. ep.Unlock()
  221. // Remove non-interface routes.
  222. for _, r := range joinInfo.StaticRoutes {
  223. if err := sb.osSbox.RemoveStaticRoute(r); err != nil {
  224. log.Debugf("Remove route failed: %v", err)
  225. }
  226. }
  227. sb.Lock()
  228. if len(sb.endpoints) == 0 {
  229. // sb.endpoints should never be empty and this is unexpected error condition
  230. // We log an error message to note this down for debugging purposes.
  231. log.Errorf("No endpoints in sandbox while trying to remove endpoint %s", ep.Name())
  232. sb.Unlock()
  233. return nil
  234. }
  235. highEpBefore := sb.endpoints[0]
  236. var (
  237. i int
  238. e *endpoint
  239. )
  240. for i, e = range sb.endpoints {
  241. if e == ep {
  242. break
  243. }
  244. }
  245. heap.Remove(&sb.endpoints, i)
  246. var highEpAfter *endpoint
  247. if len(sb.endpoints) > 0 {
  248. highEpAfter = sb.endpoints[0]
  249. }
  250. delete(sb.epPriority, ep.ID())
  251. sb.Unlock()
  252. if highEpBefore != highEpAfter {
  253. sb.updateGateway(highEpAfter)
  254. }
  255. return nil
  256. }
  257. const (
  258. defaultPrefix = "/var/lib/docker/network/files"
  259. filePerm = 0644
  260. )
  261. func (sb *sandbox) buildHostsFile() error {
  262. if sb.config.hostsPath == "" {
  263. sb.config.hostsPath = defaultPrefix + "/" + sb.id + "/hosts"
  264. }
  265. dir, _ := filepath.Split(sb.config.hostsPath)
  266. if err := createBasePath(dir); err != nil {
  267. return err
  268. }
  269. // This is for the host mode networking
  270. if sb.config.originHostsPath != "" {
  271. if err := copyFile(sb.config.originHostsPath, sb.config.hostsPath); err != nil && !os.IsNotExist(err) {
  272. return types.InternalErrorf("could not copy source hosts file %s to %s: %v", sb.config.originHostsPath, sb.config.hostsPath, err)
  273. }
  274. return nil
  275. }
  276. extraContent := make([]etchosts.Record, 0, len(sb.config.extraHosts))
  277. for _, extraHost := range sb.config.extraHosts {
  278. extraContent = append(extraContent, etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
  279. }
  280. return etchosts.Build(sb.config.hostsPath, "", sb.config.hostName, sb.config.domainName, extraContent)
  281. }
  282. func (sb *sandbox) updateHostsFile(ifaceIP string, svcRecords []etchosts.Record) error {
  283. if sb.config.originHostsPath != "" {
  284. return nil
  285. }
  286. // Rebuild the hosts file accounting for the passed interface IP and service records
  287. extraContent := make([]etchosts.Record, 0, len(sb.config.extraHosts)+len(svcRecords))
  288. for _, extraHost := range sb.config.extraHosts {
  289. extraContent = append(extraContent, etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
  290. }
  291. for _, svc := range svcRecords {
  292. extraContent = append(extraContent, svc)
  293. }
  294. return etchosts.Build(sb.config.hostsPath, ifaceIP, sb.config.hostName, sb.config.domainName, extraContent)
  295. }
  296. func (sb *sandbox) addHostsEntries(recs []etchosts.Record) {
  297. if err := etchosts.Add(sb.config.hostsPath, recs); err != nil {
  298. log.Warnf("Failed adding service host entries to the running container: %v", err)
  299. }
  300. }
  301. func (sb *sandbox) deleteHostsEntries(recs []etchosts.Record) {
  302. if err := etchosts.Delete(sb.config.hostsPath, recs); err != nil {
  303. log.Warnf("Failed deleting service host entries to the running container: %v", err)
  304. }
  305. }
  306. func (sb *sandbox) updateParentHosts() error {
  307. var pSb Sandbox
  308. for _, update := range sb.config.parentUpdates {
  309. sb.controller.WalkSandboxes(SandboxContainerWalker(&pSb, update.cid))
  310. if pSb == nil {
  311. continue
  312. }
  313. if err := etchosts.Update(pSb.(*sandbox).config.hostsPath, update.ip, update.name); err != nil {
  314. return err
  315. }
  316. }
  317. return nil
  318. }
  319. func (sb *sandbox) setupDNS() error {
  320. var newRC *resolvconf.File
  321. if sb.config.resolvConfPath == "" {
  322. sb.config.resolvConfPath = defaultPrefix + "/" + sb.id + "/resolv.conf"
  323. }
  324. sb.config.resolvConfHashFile = sb.config.resolvConfPath + ".hash"
  325. dir, _ := filepath.Split(sb.config.resolvConfPath)
  326. if err := createBasePath(dir); err != nil {
  327. return err
  328. }
  329. // This is for the host mode networking
  330. if sb.config.originResolvConfPath != "" {
  331. if err := copyFile(sb.config.originResolvConfPath, sb.config.resolvConfPath); err != nil {
  332. return fmt.Errorf("could not copy source resolv.conf file %s to %s: %v", sb.config.originResolvConfPath, sb.config.resolvConfPath, err)
  333. }
  334. return nil
  335. }
  336. currRC, err := resolvconf.Get()
  337. if err != nil {
  338. return err
  339. }
  340. if len(sb.config.dnsList) > 0 || len(sb.config.dnsSearchList) > 0 || len(sb.config.dnsOptionsList) > 0 {
  341. var (
  342. err error
  343. dnsList = resolvconf.GetNameservers(currRC.Content)
  344. dnsSearchList = resolvconf.GetSearchDomains(currRC.Content)
  345. dnsOptionsList = resolvconf.GetOptions(currRC.Content)
  346. )
  347. if len(sb.config.dnsList) > 0 {
  348. dnsList = sb.config.dnsList
  349. }
  350. if len(sb.config.dnsSearchList) > 0 {
  351. dnsSearchList = sb.config.dnsSearchList
  352. }
  353. if len(sb.config.dnsOptionsList) > 0 {
  354. dnsOptionsList = sb.config.dnsOptionsList
  355. }
  356. newRC, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList)
  357. if err != nil {
  358. return err
  359. }
  360. } else {
  361. // Replace any localhost/127.* (at this point we have no info about ipv6, pass it as true)
  362. if newRC, err = resolvconf.FilterResolvDNS(currRC.Content, true); err != nil {
  363. return err
  364. }
  365. // No contention on container resolv.conf file at sandbox creation
  366. if err := ioutil.WriteFile(sb.config.resolvConfPath, newRC.Content, filePerm); err != nil {
  367. return types.InternalErrorf("failed to write unhaltered resolv.conf file content when setting up dns for sandbox %s: %v", sb.ID(), err)
  368. }
  369. }
  370. // Write hash
  371. if err := ioutil.WriteFile(sb.config.resolvConfHashFile, []byte(newRC.Hash), filePerm); err != nil {
  372. return types.InternalErrorf("failed to write resolv.conf hash file when setting up dns for sandbox %s: %v", sb.ID(), err)
  373. }
  374. return nil
  375. }
  376. func (sb *sandbox) updateDNS(ipv6Enabled bool) error {
  377. var (
  378. currHash string
  379. hashFile = sb.config.resolvConfHashFile
  380. )
  381. if len(sb.config.dnsList) > 0 || len(sb.config.dnsSearchList) > 0 || len(sb.config.dnsOptionsList) > 0 {
  382. return nil
  383. }
  384. currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath)
  385. if err != nil {
  386. if !os.IsNotExist(err) {
  387. return err
  388. }
  389. } else {
  390. h, err := ioutil.ReadFile(hashFile)
  391. if err != nil {
  392. if !os.IsNotExist(err) {
  393. return err
  394. }
  395. } else {
  396. currHash = string(h)
  397. }
  398. }
  399. if currHash != "" && currHash != currRC.Hash {
  400. // Seems the user has changed the container resolv.conf since the last time
  401. // we checked so return without doing anything.
  402. log.Infof("Skipping update of resolv.conf file with ipv6Enabled: %t because file was touched by user", ipv6Enabled)
  403. return nil
  404. }
  405. // replace any localhost/127.* and remove IPv6 nameservers if IPv6 disabled.
  406. newRC, err := resolvconf.FilterResolvDNS(currRC.Content, ipv6Enabled)
  407. if err != nil {
  408. return err
  409. }
  410. // for atomic updates to these files, use temporary files with os.Rename:
  411. dir := path.Dir(sb.config.resolvConfPath)
  412. tmpHashFile, err := ioutil.TempFile(dir, "hash")
  413. if err != nil {
  414. return err
  415. }
  416. tmpResolvFile, err := ioutil.TempFile(dir, "resolv")
  417. if err != nil {
  418. return err
  419. }
  420. // Change the perms to filePerm (0644) since ioutil.TempFile creates it by default as 0600
  421. if err := os.Chmod(tmpResolvFile.Name(), filePerm); err != nil {
  422. return err
  423. }
  424. // write the updates to the temp files
  425. if err = ioutil.WriteFile(tmpHashFile.Name(), []byte(newRC.Hash), filePerm); err != nil {
  426. return err
  427. }
  428. if err = ioutil.WriteFile(tmpResolvFile.Name(), newRC.Content, filePerm); err != nil {
  429. return err
  430. }
  431. // rename the temp files for atomic replace
  432. if err = os.Rename(tmpHashFile.Name(), hashFile); err != nil {
  433. return err
  434. }
  435. return os.Rename(tmpResolvFile.Name(), sb.config.resolvConfPath)
  436. }
  437. // OptionHostname function returns an option setter for hostname option to
  438. // be passed to NewSandbox method.
  439. func OptionHostname(name string) SandboxOption {
  440. return func(sb *sandbox) {
  441. sb.config.hostName = name
  442. }
  443. }
  444. // OptionDomainname function returns an option setter for domainname option to
  445. // be passed to NewSandbox method.
  446. func OptionDomainname(name string) SandboxOption {
  447. return func(sb *sandbox) {
  448. sb.config.domainName = name
  449. }
  450. }
  451. // OptionHostsPath function returns an option setter for hostspath option to
  452. // be passed to NewSandbox method.
  453. func OptionHostsPath(path string) SandboxOption {
  454. return func(sb *sandbox) {
  455. sb.config.hostsPath = path
  456. }
  457. }
  458. // OptionOriginHostsPath function returns an option setter for origin hosts file path
  459. // tbeo passed to NewSandbox method.
  460. func OptionOriginHostsPath(path string) SandboxOption {
  461. return func(sb *sandbox) {
  462. sb.config.originHostsPath = path
  463. }
  464. }
  465. // OptionExtraHost function returns an option setter for extra /etc/hosts options
  466. // which is a name and IP as strings.
  467. func OptionExtraHost(name string, IP string) SandboxOption {
  468. return func(sb *sandbox) {
  469. sb.config.extraHosts = append(sb.config.extraHosts, extraHost{name: name, IP: IP})
  470. }
  471. }
  472. // OptionParentUpdate function returns an option setter for parent container
  473. // which needs to update the IP address for the linked container.
  474. func OptionParentUpdate(cid string, name, ip string) SandboxOption {
  475. return func(sb *sandbox) {
  476. sb.config.parentUpdates = append(sb.config.parentUpdates, parentUpdate{cid: cid, name: name, ip: ip})
  477. }
  478. }
  479. // OptionResolvConfPath function returns an option setter for resolvconfpath option to
  480. // be passed to net container methods.
  481. func OptionResolvConfPath(path string) SandboxOption {
  482. return func(sb *sandbox) {
  483. sb.config.resolvConfPath = path
  484. }
  485. }
  486. // OptionOriginResolvConfPath function returns an option setter to set the path to the
  487. // origin resolv.conf file to be passed to net container methods.
  488. func OptionOriginResolvConfPath(path string) SandboxOption {
  489. return func(sb *sandbox) {
  490. sb.config.originResolvConfPath = path
  491. }
  492. }
  493. // OptionDNS function returns an option setter for dns entry option to
  494. // be passed to container Create method.
  495. func OptionDNS(dns string) SandboxOption {
  496. return func(sb *sandbox) {
  497. sb.config.dnsList = append(sb.config.dnsList, dns)
  498. }
  499. }
  500. // OptionDNSSearch function returns an option setter for dns search entry option to
  501. // be passed to container Create method.
  502. func OptionDNSSearch(search string) SandboxOption {
  503. return func(sb *sandbox) {
  504. sb.config.dnsSearchList = append(sb.config.dnsSearchList, search)
  505. }
  506. }
  507. // OptionDNSOptions function returns an option setter for dns options entry option to
  508. // be passed to container Create method.
  509. func OptionDNSOptions(options string) SandboxOption {
  510. return func(sb *sandbox) {
  511. sb.config.dnsOptionsList = append(sb.config.dnsOptionsList, options)
  512. }
  513. }
  514. // OptionUseDefaultSandbox function returns an option setter for using default sandbox to
  515. // be passed to container Create method.
  516. func OptionUseDefaultSandbox() SandboxOption {
  517. return func(sb *sandbox) {
  518. sb.config.useDefaultSandBox = true
  519. }
  520. }
  521. // OptionGeneric function returns an option setter for Generic configuration
  522. // that is not managed by libNetwork but can be used by the Drivers during the call to
  523. // net container creation method. Container Labels are a good example.
  524. func OptionGeneric(generic map[string]interface{}) SandboxOption {
  525. return func(sb *sandbox) {
  526. sb.config.generic = generic
  527. }
  528. }
  529. func (eh epHeap) Len() int { return len(eh) }
  530. func (eh epHeap) Less(i, j int) bool {
  531. ci, _ := eh[i].getSandbox()
  532. cj, _ := eh[j].getSandbox()
  533. cip, ok := ci.epPriority[eh[i].ID()]
  534. if !ok {
  535. cip = 0
  536. }
  537. cjp, ok := cj.epPriority[eh[j].ID()]
  538. if !ok {
  539. cjp = 0
  540. }
  541. if cip == cjp {
  542. return eh[i].getNetwork().Name() < eh[j].getNetwork().Name()
  543. }
  544. return cip > cjp
  545. }
  546. func (eh epHeap) Swap(i, j int) { eh[i], eh[j] = eh[j], eh[i] }
  547. func (eh *epHeap) Push(x interface{}) {
  548. *eh = append(*eh, x.(*endpoint))
  549. }
  550. func (eh *epHeap) Pop() interface{} {
  551. old := *eh
  552. n := len(old)
  553. x := old[n-1]
  554. *eh = old[0 : n-1]
  555. return x
  556. }
  557. func createBasePath(dir string) error {
  558. return os.MkdirAll(dir, filePerm)
  559. }
  560. func createFile(path string) error {
  561. var f *os.File
  562. dir, _ := filepath.Split(path)
  563. err := createBasePath(dir)
  564. if err != nil {
  565. return err
  566. }
  567. f, err = os.Create(path)
  568. if err == nil {
  569. f.Close()
  570. }
  571. return err
  572. }
  573. func copyFile(src, dst string) error {
  574. sBytes, err := ioutil.ReadFile(src)
  575. if err != nil {
  576. return err
  577. }
  578. return ioutil.WriteFile(dst, sBytes, filePerm)
  579. }