1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/graph
Kir Kolyshkin a83a769347 Simplify and fix os.MkdirAll() usage
TL;DR: check for IsExist(err) after a failed MkdirAll() is both
redundant and wrong -- so two reasons to remove it.

Quoting MkdirAll documentation:

> MkdirAll creates a directory named path, along with any necessary
> parents, and returns nil, or else returns an error. If path
> is already a directory, MkdirAll does nothing and returns nil.

This means two things:

1. If a directory to be created already exists, no error is returned.

2. If the error returned is IsExist (EEXIST), it means there exists
a non-directory with the same name as MkdirAll need to use for
directory. Example: we want to MkdirAll("a/b"), but file "a"
(or "a/b") already exists, so MkdirAll fails.

The above is a theory, based on quoted documentation and my UNIX
knowledge.

3. In practice, though, current MkdirAll implementation [1] returns
ENOTDIR in most of cases described in #2, with the exception when
there is a race between MkdirAll and someone else creating the
last component of MkdirAll argument as a file. In this very case
MkdirAll() will indeed return EEXIST.

Because of #1, IsExist check after MkdirAll is not needed.

Because of #2 and #3, ignoring IsExist error is just plain wrong,
as directory we require is not created. It's cleaner to report
the error now.

Note this error is all over the tree, I guess due to copy-paste,
or trying to follow the same usage pattern as for Mkdir(),
or some not quite correct examples on the Internet.

[v2: a separate aufs commit is merged into this one]

[1] https://github.com/golang/go/blob/f9ed2f75/src/os/path.go

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
2015-07-30 11:48:08 -07:00
..
tags Check if a tag name to load is a valid digest. 2015-07-16 10:53:56 -07:00
export.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
graph.go Simplify and fix os.MkdirAll() usage 2015-07-30 11:48:08 -07:00
graph_test.go Replace GenerateRandomID with GenerateNonCryptoID 2015-07-28 22:31:01 -07:00
graph_unix.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
graph_windows.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
history.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
import.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
list.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
load.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
load_unsupported.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
mutex.go Attempt to protect on disk image store with mutex 2015-06-25 20:16:37 -07:00
pools_test.go don't call reexec.Init from chrootarchive 2014-11-25 01:03:40 +02:00
pull.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
pull_v1.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
pull_v2.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
push.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
push_v1.go Improve documentation and golint compliance of registry package 2015-07-24 11:55:07 -07:00
push_v2.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
registry.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
service.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
tags.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00
tags_unit_test.go /graph fix lin errors/warnings 2015-07-29 20:59:36 +00:00