Skip to content

Commit

Permalink
osprepare: deadcode: Remove never used isUbuntuDockerRepoEnabled()
Browse files Browse the repository at this point in the history
The removal of this unused leaf function allowed the removal of other
functions and structures for inspecting the APT sources list that this
function used in its implementation.

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed May 18, 2017
1 parent 0276e02 commit 3b59224
Showing 1 changed file with 0 additions and 135 deletions.
135 changes: 0 additions & 135 deletions osprepare/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,147 +22,12 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"

"github.com/01org/ciao/clogger"
)

const (
aptSourcesList = "/etc/apt/sources.list"
aptSourcesListD = "/etc/apt/sources.list.d"
)

// aptSourcesFile abstracts a source.list file into
// a list of aptSource structs and the file where
// those definitions are located.
// Each apt source list may have multiple sources
type aptSourcesFile struct {
Sources []*aptSource
Path string
}

// aptSource struct contains all the fields
// in an apt line in /etc/apt/sources.list
// e.g:
// deb|deb-src $origin $distribution $component1 $component2
type aptSource struct {
DebType string
Origin string
Distribution string
Components []string
}

// readAptSourcesFile reads a sources.list style file
// and return an aptSourcesFile
func readAptSourcesFile(path string) *aptSourcesFile {
fi, err := os.Open(path)

if err != nil {
return nil
}

ret := aptSourcesFile{Path: path}

defer fi.Close()
sc := bufio.NewScanner(fi)
for sc.Scan() {
line := sc.Text()

line = strings.TrimSpace(line)

// Skip blanks..
if len(line) < 1 {
continue
}

// Skip comment lines
if line[0] == '#' {
continue
}

if rs := newAptSource(line); rs != nil {
ret.Sources = append(ret.Sources, rs)
}
// Could warn here, but that's overkill.
}
return &ret
}

// loadAptSources reads the apt source files
// defined by aptSourcesList and aptSourcesListD
// returning a list of aptSourcesFile containing
// all sources defined in the distro
func loadAptSources() []*aptSourcesFile {
var sources []*aptSourcesFile

// Closure is only relevant to this function
addAptSources := func(path string) {
if r := readAptSourcesFile(path); r != nil {
sources = append(sources, r)
}
}

if pathExists(aptSourcesList) {
addAptSources(aptSourcesList)
}

// Glob the *.list files now
if pathExists(aptSourcesListD) {
tpath := fmt.Sprintf("%s/*.list", aptSourcesListD)
if files, err := filepath.Glob(tpath); err == nil {
for _, file := range files {
addAptSources(file)
}
}
}

return sources
}

// newAptSource constructs a new apt source from
// the given deb style line
func newAptSource(debLine string) *aptSource {
fields := strings.Fields(debLine)
var asource aptSource

if len(fields) < 3 {
return nil
}

dtype := fields[0]
if dtype != "deb" && dtype != "deb-src" {
return nil
}

asource.DebType = dtype
asource.Origin = fields[1]
asource.Distribution = fields[2]
if len(fields) > 3 {
asource.Components = fields[3:]
}

return &asource
}

// isUbuntuDockerRepoEnabled iterates through the sources
// to find out if the docker repo is enabled or not.
func isUbuntuDockerRepoEnabled() bool {
sources := loadAptSources()
if sources == nil {
return false
}
for _, sourceFile := range sources {
for _, source := range sourceFile.Sources {
if strings.Contains(source.Origin, "apt.dockerproject.org") {
return true
}
}
}
return false
}

// pathExists is a helper function which handles the
// error and simply return true or false if the given
// path exists
Expand Down

0 comments on commit 3b59224

Please sign in to comment.