omit uname/gname in tar headers
When using cache, the rootfs may not have been extracted. This prevents uname/gname from resolving as there is no /etc/password or /etc/group. This makes this layer unnecessarily differ from a cached layer which does contain this information. Omitting these should be consistent with Docker's behavior.
This commit is contained in:
		
							parent
							
								
									cc2c9a0663
								
							
						
					
					
						commit
						82bce229bd
					
				|  | @ -371,6 +371,36 @@ func TestSnasphotPreservesFileOrder(t *testing.T) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestSnapshotOmitsUnameGname(t *testing.T) { | ||||
| 	testDir, snapshotter, cleanup, err := setUpTestDir() | ||||
| 	testDirWithoutLeadingSlash := strings.TrimLeft(testDir, "/") | ||||
| 	defer cleanup() | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	tarPath, err := snapshotter.TakeSnapshotFS() | ||||
| 
 | ||||
| 	f, err := os.Open(tarPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 	tr := tar.NewReader(f) | ||||
| 	for { | ||||
| 		hdr, err := tr.Next() | ||||
| 		if err == io.EOF { | ||||
| 			break | ||||
| 		} | ||||
| 		if err != nil { | ||||
| 			t.Fatal(err) | ||||
| 		} | ||||
| 		if hdr.Uname != "" || hdr.Gname != "" { | ||||
| 			t.Fatalf("Expected Uname/Gname for %s to be empty: Uname = '%s', Gname = '%s'", hdr.Name, hdr.Uname, hdr.Gname) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func setupSymlink(dir string, link string, target string) error { | ||||
| 	return os.Symlink(target, filepath.Join(dir, link)) | ||||
| } | ||||
|  |  | |||
|  | @ -84,6 +84,11 @@ func (t *Tar) AddFileToTar(p string) error { | |||
| 		hdr.Name = p | ||||
| 	} | ||||
| 
 | ||||
|   // rootfs may not have been extracted when using cache, preventing uname/gname from resolving
 | ||||
|   // this makes this layer unnecessarily differ from a cached layer which does contain this information
 | ||||
|   hdr.Uname = "" | ||||
|   hdr.Gname = "" | ||||
| 
 | ||||
| 	hardlink, linkDst := t.checkHardlink(p, i) | ||||
| 	if hardlink { | ||||
| 		hdr.Linkname = linkDst | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue