pkg/archive
Kir Kolyshkin fe45bb6d4d 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
..
testdata Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
archive.go Simplify and fix os.MkdirAll() usage 2015-07-30 11:48:08 -07:00
archive_test.go pkg/archive: new utilities for copying resources 2015-07-21 11:03:25 -07:00
archive_unix.go linting changes 2015-06-17 01:16:57 +03:00
archive_unix_test.go pkg/archive: adjust chmod bits on windows 2015-03-04 14:10:37 -08:00
archive_windows.go Windows: Archive package changes for Windows daemon 2015-05-20 08:55:54 -07:00
archive_windows_test.go trivial: typo cleanup 2015-04-27 13:35:08 -07:00
changes.go Windows: Docker build starting to work 2015-06-17 10:41:28 -07:00
changes_linux.go ino and dev must both match for a file to be identical. 2015-05-05 11:06:54 -04:00
changes_other.go Windows: Docker build starting to work 2015-06-17 10:41:28 -07:00
changes_posix_test.go pkg/archive: test that confirms hardlink ordering 2015-02-06 18:14:38 +01:00
changes_test.go Add the parent directory to changes set if new files are generated 2015-06-10 20:29:29 +08:00
changes_unix.go Windows: Archive package changes for Windows daemon 2015-05-20 08:55:54 -07:00
changes_windows.go Windows: Archive package changes for Windows daemon 2015-05-20 08:55:54 -07:00
copy.go Fix log to logrus 2015-07-29 09:58:07 -07:00
copy_test.go *: s/direcotry/directory/g typo 2015-07-27 11:29:28 -04:00
diff.go archive, chrootarchive: split out decompression 2015-07-28 16:36:38 -04:00
diff_test.go Finally remove our copy of "archive/tar" now that Go 1.4 is the minimum! 2015-05-01 16:01:10 -06:00
example_changes.go archive: example app for diffing directories 2014-10-29 14:52:59 -04:00
README.md Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
time_linux.go Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
time_unsupported.go Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
utils_test.go linting changes 2015-06-17 01:16:57 +03:00
wrap.go Finally remove our copy of "archive/tar" now that Go 1.4 is the minimum! 2015-05-01 16:01:10 -06:00
wrap_test.go Add coverage on pkg/archive 2015-04-24 17:03:33 +02:00

This code provides helper functions for dealing with archive files.