Repository: uber/makisu
Pull request #196 (2019-03-18 22:47:55)

Check mode of files and dirs in addition to mtime
chmod doesn't update file mtime.


Patch:
diff --git a/bin/makisu/README.md b/bin/makisu/README.md
index 3c14838..78c06c0 100644
--- a/bin/makisu/README.md
+++ b/bin/makisu/README.md
@@ -34,7 +34,7 @@ Flags:
 Global Flags:
       --cpu-profile         Profile the application
       --log-fmt string      The format of the logs. Valid values are "json" and "console" (default "json")
-      --log-level string    Verbose level of logs. Valid values are "trace", "debug", "info", "warn", "error", "fatal" (default "info")
+      --log-level string    Verbose level of logs. Valid values are "debug", "info", "warn", "error" (default "info")
       --log-output string   The output file path for the logs. Set to "stdout" to output to stdout (default "stdout")
 
 $ makisu version
diff --git a/bin/makisu/cmd/root.go b/bin/makisu/cmd/root.go
index 93ac135..606bf36 100644
--- a/bin/makisu/cmd/root.go
+++ b/bin/makisu/cmd/root.go
@@ -45,7 +45,7 @@ func getRootCmd() *rootCmd {
 		},
 	}
 
-	rootCmd.PersistentFlags().StringVar(&rootCmd.logLevel, "log-level", "info", "Verbose level of logs. Valid values are \"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"")
+	rootCmd.PersistentFlags().StringVar(&rootCmd.logLevel, "log-level", "info", "Verbose level of logs. Valid values are \"debug\", \"info\", \"warn\", \"error\"")
 	rootCmd.PersistentFlags().StringVar(&rootCmd.logOutput, "log-output", "stdout", "The output file path for the logs. Set to \"stdout\" to output to stdout")
 	rootCmd.PersistentFlags().StringVar(&rootCmd.logFormat, "log-fmt", "json", "The format of the logs. Valid values are \"json\" and \"console\"")
 	rootCmd.PersistentFlags().BoolVar(&rootCmd.cpuProfile, "cpu-profile", false, "Profile the application")
diff --git a/lib/tario/compare.go b/lib/tario/compare.go
index a564f4a..f9bbdce 100644
--- a/lib/tario/compare.go
+++ b/lib/tario/compare.go
@@ -59,7 +59,8 @@ func isSimilarHardLink(h *tar.Header, nh *tar.Header) (bool, error) {
 	if hMtime.Equal(nhMtime) &&
 		h.Linkname == nh.Linkname &&
 		h.Uid == nh.Uid &&
-		h.Gid == nh.Gid {
+		h.Gid == nh.Gid &&
+		h.Mode == nh.Mode {
 		return true, nil
 	}
 	return false, nil
@@ -72,7 +73,8 @@ func isSimilarDirectory(h *tar.Header, nh *tar.Header) (bool, error) {
 	nhMtime := nh.ModTime.Truncate(1 * time.Second)
 	if hMtime.Equal(nhMtime) &&
 		h.Uid == nh.Uid &&
-		h.Gid == nh.Gid {
+		h.Gid == nh.Gid &&
+		h.Mode == nh.Mode {
 		return true, nil
 	}
 	return false, nil
@@ -86,7 +88,8 @@ func isSimilarRegularFile(h *tar.Header, nh *tar.Header) (bool, error) {
 	if hMtime.Equal(nhMtime) &&
 		h.Uid == nh.Uid &&
 		h.Gid == nh.Gid &&
-		h.Size == nh.Size {
+		h.Size == nh.Size &&
+		h.Mode == nh.Mode {
 		return true, nil
 	}
 	return false, nil


Test patch:
diff --git a/lib/tario/compare_test.go b/lib/tario/compare_test.go
index 6b6188d..9eb14d6 100644
--- a/lib/tario/compare_test.go
+++ b/lib/tario/compare_test.go
@@ -440,6 +440,36 @@ func TestIsSimilarDirectory(t *testing.T) {
 		require.NoError(err)
 	})
 
+	t.Run("DifferentModeConsideredDifferent", func(t *testing.T) {
+		require := require.New(t)
+
+		tmpRoot, err := ioutil.TempDir("/tmp", "makisu-test")
+		require.NoError(err)
+		defer os.RemoveAll(tmpRoot)
+
+		testDir1, err := ioutil.TempDir(tmpRoot, "test1")
+		require.NoError(err)
+		testDir2, err := ioutil.TempDir(tmpRoot, "test2")
+		require.NoError(err)
+
+		require.NoError(os.Chmod(testDir1, os.FileMode(0777)))
+
+		fi1, err := os.Lstat(testDir1)
+		require.NoError(err)
+		fi2, err := os.Lstat(testDir2)
+		require.NoError(err)
+
+		h, err := tar.FileInfoHeader(fi1, "")
+		require.NoError(err)
+		newH, err := tar.FileInfoHeader(fi2, "")
+		require.NoError(err)
+		similar, err := isSimilarDirectory(h, newH)
+		require.False(similar)
+		require.NoError(err)
+		similar, err = IsSimilarHeader(h, newH)
+		require.False(similar)
+		require.NoError(err)
+	})
 }
 
 func TestIsSimilarRegularFile(t *testing.T) {
@@ -582,4 +612,35 @@ func TestIsSimilarRegularFile(t *testing.T) {
 		require.False(similar)
 		require.NoError(err)
 	})
+
+	t.Run("DifferentModeConsideredDifferent", func(t *testing.T) {
+		require := require.New(t)
+
+		tmpRoot, err := ioutil.TempDir("/tmp", "makisu-test")
+		require.NoError(err)
+		defer os.RemoveAll(tmpRoot)
+
+		testFile1, err := ioutil.TempFile(tmpRoot, "test1")
+		require.NoError(err)
+		testFile2, err := ioutil.TempFile(tmpRoot, "test2")
+		require.NoError(err)
+
+		require.NoError(os.Chmod(testFile1.Name(), os.FileMode(0777)))
+
+		fi1, err := os.Lstat(testFile1.Name())
+		require.NoError(err)
+		fi2, err := os.Lstat(testFile2.Name())
+		require.NoError(err)
+
+		h, err := tar.FileInfoHeader(fi1, "")
+		require.NoError(err)
+		newH, err := tar.FileInfoHeader(fi2, "")
+		require.NoError(err)
+		similar, err := isSimilarRegularFile(h, newH)
+		require.False(similar)
+		require.NoError(err)
+		similar, err = IsSimilarHeader(h, newH)
+		require.False(similar)
+		require.NoError(err)
+	})
 }