moby--moby/libnetwork/sandbox
Kir Kolyshkin 140616a7d6 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.

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

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
2015-07-29 18:09:42 -07:00
..
interface_freebsd.go make libnetwork compile on freebsd (again) 2015-07-21 19:41:01 +03:00
interface_linux.go Endpoint interface stats read fails when invoked from docker 2015-06-29 20:29:41 -07:00
interface_windows.go Windows: Compiles again 2015-06-12 12:40:36 -07:00
namespace_linux.go Simplify and fix os.MkdirAll() usage 2015-07-29 18:09:42 -07:00
namespace_unsupported.go make libnetwork compile on freebsd (again) 2015-07-21 19:41:01 +03:00
namespace_windows.go Windows: Compiles again 2015-06-12 12:40:36 -07:00
neigh_freebsd.go make libnetwork compile on freebsd (again) 2015-07-21 19:41:01 +03:00
neigh_linux.go Add neighbor support to sandbox 2015-06-18 15:07:17 -07:00
neigh_windows.go Fixing a windows compile error in docker during vendor-in 2015-06-21 02:32:07 -07:00
options_linux.go Add neighbor support to sandbox 2015-06-18 15:07:17 -07:00
route_linux.go deadlock fix in RemoveStaticRoute 2015-07-24 01:32:35 -07:00
sandbox.go Endpoint to expose interfaces' statistics 2015-06-29 16:15:31 -07:00
sandbox_freebsd.go make libnetwork compile on freebsd (again) 2015-07-21 19:41:01 +03:00
sandbox_linux_test.go Endpoint to expose interfaces' statistics 2015-06-29 16:15:31 -07:00
sandbox_test.go Make sure sandbox files are removed after tests 2015-06-11 14:55:17 -07:00
sandbox_unsupported.go make libnetwork compile on freebsd (again) 2015-07-21 19:41:01 +03:00
sandbox_unsupported_test.go Added unsupported implementations for sandbox and sandbox 2015-04-14 04:53:02 +00:00