-
Notifications
You must be signed in to change notification settings - Fork 775
oci-image-tool: Cleanup partially-unpacked directories on failures #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
does it make sense to unpack to a temp dir and then os.Rename? to have something more atomic somehow (on error just throw off the temp) |
|
aiyeee, I really don't like this code. There is (probably?) a breakout if this is hit (removing a path outside the tarball) - and if I'm wrong about that one I'd bet there are other corner cases not covered yet. Can we use some existing, well-tested tar extracting code instead? |
|
This is already coming from Docker code which is imo well tested. Not sure about other options. |
|
On Fri, Sep 02, 2016 at 07:18:51AM -0700, Jonathan Boulle wrote:
Yeah, that looks like a bug to me. You could fix it by moving: entries[path] = true after the check. But I think this per-layer unwinding approach is trying too hard. And os.RemoveAll(dest) in unpack if any of the unpackLayer calls failed. |
it's does a bug here, thank you for pointing out:) @wking I has thought about @runcom Do you mean we unpack the layer to a tmp file and then rename to Thank you all for reviewing, I'll work on this tomorrow :) |
|
On Fri, Sep 02, 2016 at 09:43:44AM -0700, Lei Jitang wrote:
I think it should be an error if there is anything in ‘dest’ before |
c94c189 to
dbd6607
Compare
|
@wking that's make sense. |
image/manifest.go
Outdated
| func (m *manifest) unpack(w walker, dest string) (retErr error) { | ||
| // error out if the dest directory is not empty | ||
| if _, err := os.Stat(dest); err == nil { | ||
| s, _ := ioutil.ReadDir(dest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need both Stat and ReadDir. If you want to error out if there is an entry at that path, just use Stat. If you want to error out unless the path has no entry or contains an empty directory, just use ReadDir. The latter sounds better to me (you can use it with mktemp -d), but I'm ok with either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if you end up using ReadDir, you should be checking for errors that it returns and returning those, instead of returning your own “is not empty” error in those cases (e.g. maybe the directory is not empty, but you lack read permission).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wking Thanks, will update
6451e5c to
aa6be98
Compare
|
@wking updated |
image/manifest.go
Outdated
| // error out if the dest directory is not empty | ||
| if s, err := ioutil.ReadDir(dest); err != nil && !os.IsNotExist(err) || len(s) > 0 { | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open %s: %v", dest, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use errors.Wrap instead of fmt.Errorf? There is a lot of existing use of errors.Wrap in this package.
aa6be98 to
7684889
Compare
|
@wking updated, thanks :) |
|
7684889 looks good to me.
|
|
Looks good but can you add a test for this please? |
7684889 to
b0200b1
Compare
0d0414f to
781b8ff
Compare
Signed-off-by: Lei Jitang <[email protected]>
Signed-off-by: Lei Jitang <[email protected]>
|
@wking Should we continue this after splitting tool to a separate repo? |
|
On Wed, Sep 14, 2016 at 12:32:40AM -0700, Lei Jitang wrote:
If you like. I'm a maintainer of neither, but I see no reason to |
Signed-off-by: Lei Jitang [email protected]
fixes #242
cc @runcom @wking