title: how can I update a file in tarball?
body: <p>How can I update a file in tarball with Go?</p>
  <p>I can only find some way to append file into a tar file like this:</p>
  <pre><code>file, err := os.OpenFile(path, os.O_WRONLY, 0644)
  if _, err = file.Seek(-1024, os.SEEK_END); err != nil {
      log.Fatalln(err)
  }
  if err != nil { return err }
  defer file.Close()
  tw := tar.NewWriter(file)
  hdr := &amp;tar.Header{
      Name: &quot;manifest.json&quot;,
      Mode: 0644,
      Size: int64(len(content)),
  }
  if err := tw.WriteHeader(hdr); err != nil {
      log.Fatal(err)
  }
  if _, err := tw.Write(content); err != nil {
      log.Fatal(err)
  }
  if err := tw.Close(); err != nil {
      log.Fatal(err)
  }
  </code></pre>
  <hr />
  <p>After finding solutions by google ,it seemed I have some commands like <code>tar uvf ...</code> or try to extract the tarball and make a new one by golang or command <code>tar</code>.</p>
  <p>As tar document says , command <code>tar uf</code> can update a file in tar ball directly, but after using <code>tar uvf</code> , I found a very interesting thing like below:</p>
  <p>a.tar is a docker image made by <code>docker image save</code></p>
  <p>I want to change manifest.json file in thie docker image tarball by <code>tar uvf a.tar manifest.json</code>
  before update, the content of tarball seems OK.</p>
  <pre><code>[root@master1 a]# ls
  a.tar
  [root@master1 a]# tar xf a.tar 
  tar: manifest.json: implausibly old time stamp 1970-01-01 08:00:00
  tar: repositories: implausibly old time stamp 1970-01-01 08:00:00
  [root@master1 a]# ls
  2080c332033e330242f9ea2043e18c7ea98de2ee1b1b3921b1a33bcb84ac4cd5
  2acf0fc34f8cc199bde6f74a7d85382461ff69cf4618e5964e7e1d19d0fe1d5c
  3962220e6895f5a8c88034ae1bc7926b9bb40ecdc441196cd01c7cf36e36b7db.json
  a7d478578679c443a1d4e695154dbbe8cad5525ac46fa80e925c2a080d0b620f
  a.tar
  c2103589e99f907333422ae78702360ad258a8f0366c20e341c9e0c53743e78a.json
  da70bf0a87b384edc6cfc5cff3a33ba087de7b81f914df73181bfc2869314ebb
  manifest.json
  repositories
  </code></pre>
  <p>then I try to update manifest.json by <code>tar uvf a.tar manifest.json</code></p>
  <pre><code>[root@master1 b]# ls
  a.tar
  [root@master1 b]# tar xf a.tar 
  tar: Skipping to next header
  tar: Exiting with failure status due to previous errors
  [root@master1 b]# ls -al
  total 65972
  drwxr-xr-x 6 root root     4096 Apr 26 15:28 .
  drwxr-xr-x 4 root root     4096 Apr 26 15:28 ..
  drwxr-xr-x 2 root root     4096 Sep 10  2019 2080c332033e330242f9ea2043e18c7ea98de2ee1b1b3921b1a33bcb84ac4cd5
  drwxr-xr-x 2 root root     4096 Dec 31  2019 2acf0fc34f8cc199bde6f74a7d85382461ff69cf4618e5964e7e1d19d0fe1d5c
  -rw-r--r-- 1 root root     2429 Dec 31  2019 3962220e6895f5a8c88034ae1bc7926b9bb40ecdc441196cd01c7cf36e36b7db.json
  drwxr-xr-x 2 root root     4096 Dec 31  2019 a7d478578679c443a1d4e695154dbbe8cad5525ac46fa80e925c2a080d0b620f
  -rw-r--r-- 1 root root 67517440 Apr 26 15:28 a.tar
  -rw-r--r-- 1 root root     2467 Sep 10  2019 c2103589e99f907333422ae78702360ad258a8f0366c20e341c9e0c53743e78a.json
  drwxr-xr-x 2 root root     4096 Sep 10  2019 da70bf0a87b384edc6cfc5cff3a33ba087de7b81f914df73181bfc2869314ebb
  </code></pre>
  <p>As you can see, <code>manifest.json</code> and <code>repositories</code> disappeared . And sometimes , there will be a <code>var</code> directory.  This is very strange .</p>
  <p>Thanks a lot if someone can tell me why.</p>
  <hr />
  <p>After trying use command <code>7za d</code> and <code>7za a</code>, I change a file in a tarball successfully .</p>