Skip to content

Commit

Permalink
Remove unnecessary Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Aug 8, 2019
1 parent 6a0d089 commit 0a179ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
5 changes: 2 additions & 3 deletions installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ func InstallDotfile(dotfile *PreparedDotfile, config InstallConfig) error {
return os.Remove(installPath)
}

targetMode := dotfile.Permissions.New | dotfile.Mode.New
targetMode := dotfile.Permissions.New

// Only filemode differs
modeChanged := !dotfile.IsNew &&
!dotfile.ContentsDiffer &&
(dotfile.Permissions.IsChanged() || dotfile.Mode.IsChanged())
!dotfile.ContentsDiffer && dotfile.Permissions.IsChanged()

if modeChanged {
return os.Chmod(installPath, targetMode)
Expand Down
16 changes: 2 additions & 14 deletions installer/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ type PreparedDotfile struct {
// compiled or installed.
SourcesAreIrregular bool

// Mode represents the change in the file mode bits of the source and
// target os.FileMode (does not include permissions). This will not be set
// if the sources are irregular.
Mode FileMode

// Permissions represents the change in permission between the compiled source
// and the currently installed dotfile. Equal permissions can be verified
// by calling Permissions.IsSame.
Expand All @@ -67,7 +62,7 @@ type PreparedDotfile struct {
// IsChanged reports if the prepared dotfile has changes from the target
// dotfile.
func (p *PreparedDotfile) IsChanged() bool {
return p.IsNew || p.Added || p.Removed || p.ContentsDiffer || p.Permissions.IsChanged() || p.Mode.IsChanged()
return p.IsNew || p.Added || p.Removed || p.ContentsDiffer || p.Permissions.IsChanged()
}

// FileMode represents the new and old dotfile file mode.
Expand Down Expand Up @@ -165,17 +160,10 @@ func PrepareDotfiles(dotfiles resolver.Dotfiles, config config.SourceConfig) Pre
Old: targetMode & os.ModePerm,
New: sourcePermissions,
}
prepared.SourcePermissionsDiffer = tookLowest

prepared.SourcePermissionsDiffer = tookLowest
prepared.SourcesAreIrregular = !isAllRegular(sourceInfo)

if len(sourceInfo) > 0 && !prepared.SourcesAreIrregular {
prepared.Mode = FileMode{
Old: targetMode &^ os.ModePerm,
New: sourceInfo[0].Mode() &^ os.ModePerm,
}
}

// Nothing needs to be verified if the dotfile is being added or removed.
if !exists || dotfile.Removed {
return
Expand Down
4 changes: 2 additions & 2 deletions output/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ func (l *Output) DotfileInfo(dotfile *installer.PreparedDotfile) {
)
}

fmt.Println()

ln := func(v ...interface{}) {
fmt.Printf(" %s %s\n", v...)
}

fmt.Println()

if dotfile.PrepareError != nil {
ln(e, color.HiRedString(dotfile.PrepareError.Error()))
}
Expand Down

0 comments on commit 0a179ec

Please sign in to comment.