Skip to content

Commit

Permalink
changed to also ignore whitespace-only and fixed review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Oct 6, 2015
1 parent e1ec438 commit 3a907ed
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions installer-resources/lantern.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (client *Client) newReverseProxy() (*httputil.ReverseProxy, error) {
dialer, conn, err := client.getBalancer().TrustedDialerAndConn()
if err != nil {
// The internal code has already reported an error here.
log.Debugf("Could not get balanced dialer", err)
log.Debugf("Could not get balanced dialer %v", err)
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion src/github.com/getlantern/flashlight/config/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func MakeInitialConfig(configPath string) error {
// Get the yaml file from either the local file system or from an
// embedded resource, but ignore local file system files if they're
// empty.
bytes, err := fs.GetIgnoreEmpty("lantern.yaml")
bytes, err := fs.GetIgnoreLocalEmpty("lantern.yaml")
if err != nil {
log.Errorf("Could not read bootstrap file %v", err)
return err
Expand Down
1 change: 1 addition & 0 deletions src/github.com/getlantern/tarfs/localresources/empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

20 changes: 8 additions & 12 deletions src/github.com/getlantern/tarfs/tarfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (fs *FileSystem) SubDir(dir string) *FileSystem {
}
}

// GetIgnoreEmpty is the same as Get, but it ignores local file system files
// GetIgnoreLocalEmpty is the same as Get, but it ignores local file system files
// if they're empty.
func (fs *FileSystem) GetIgnoreEmpty(p string) ([]byte, error) {
func (fs *FileSystem) GetIgnoreLocalEmpty(p string) ([]byte, error) {
return fs.get(p, true)
}

Expand All @@ -128,13 +128,6 @@ func (fs *FileSystem) Get(p string) ([]byte, error) {
return fs.get(p, false)
}

// Get returns the bytes for the resource at the given path. If this FileSystem
// was configured with a local directory, and that local directory contains
// a file at the given path, Get will return the value from the local file.
// Otherwise, it returns the bytes from the embedded in-memory resource.
//
// Note - the implementation of local reads is not optimized and is primarily
// intended for development-time usage.
func (fs *FileSystem) get(p string, ignoreempty bool) ([]byte, error) {
p = path.Clean(p)
log.Tracef("Getting %v", p)
Expand All @@ -149,9 +142,12 @@ func (fs *FileSystem) get(p string, ignoreempty bool) ([]byte, error) {
} else if !ignoreempty {
log.Tracef("Using local resource %v", p)
return b, nil
} else if len(b) > 0 {
log.Tracef("Using local non-empty resource %v", p)
return b, nil
} else {
trimmed := strings.TrimSpace(string(b))
if len(trimmed) > 0 {
log.Tracef("Using local non-empty resource %v", p)
return b, nil
}
}
}
b, found := fs.files[p]
Expand Down
7 changes: 5 additions & 2 deletions src/github.com/getlantern/tarfs/tarfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ func TestIgnoreEmpty(t *testing.T) {
t.Fatalf("Unable to open filesystem: %v", err)
}

// Test to make sure we get the file if we're not ignoring empty.
// Note empty on disk actually has a single space to allow us to
// check it into git, but the method ignores whitespace.
a, err := fs.Get("empty.txt")
if assert.NoError(t, err, "empty.txt should have loaded") {
assert.Equal(t, "", string(a), "A should have matched expected")
assert.Equal(t, " \n", string(a), "A should have matched expected")
}

// We artificially change the entry for empty byte in the file system
// to make sure we get the file system and not the local version.
emptyBytes := []byte("empty")
fs.files["empty.txt"] = emptyBytes

a, err = fs.GetIgnoreEmpty("empty.txt")
a, err = fs.GetIgnoreLocalEmpty("empty.txt")
if assert.NoError(t, err, "empty.txt should have loaded") {
assert.Equal(t, string(emptyBytes), string(a), "A should have matched expected")
}
Expand Down

0 comments on commit 3a907ed

Please sign in to comment.