an [abandoned] attempt to slice out the docker/docker/pkg package
Find a file
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
ansiescape Use notary library for trusted image fetch and signing 2015-07-24 14:08:20 -07:00
archive Simplify and fix os.MkdirAll() usage 2015-07-30 11:48:08 -07:00
broadcastwriter remove dead code after decoupling from jsonlog 2015-07-21 20:47:35 -04:00
chrootarchive Windows: Daemon build is broken 2015-07-29 20:08:51 -07:00
devicemapper devicemapper: Check loop devices of existing pool 2015-07-07 14:13:29 -04:00
directory make docker compile on freebsd 2015-07-29 21:25:56 +03:00
fileutils Add missing tests and docs for pkg/fileutils 2015-07-12 22:43:42 +02:00
graphdb Windows: Statically linkable SQLite3 2015-07-21 09:33:46 -07:00
homedir Update libcontainer 2015-07-16 16:02:26 -07:00
httputils Fixed outdated comment. 2015-07-02 08:17:11 -03:00
ioutils Fix reset timeout for buffer readers. 2015-07-28 14:30:18 -07:00
jsonlog remove dead code after decoupling from jsonlog 2015-07-21 20:47:35 -04:00
jsonmessage Add test coverage to pkg/jsonmessage 2015-06-02 21:19:38 +02:00
listenbuffer linting changes 2015-06-17 01:16:57 +03:00
mflag Fix golint for pkg/mflag 2015-07-28 15:32:42 +02:00
mount pkg: mount: golint 2015-07-22 10:26:10 +02:00
namesgenerator Use global random *rand.Rand instance in pkg 2015-07-29 09:30:48 -07:00
nat Fix go vet errors 2015-07-25 17:00:10 -04:00
parsers make docker compile on freebsd 2015-07-29 21:25:56 +03:00
pidfile Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
plugins Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
pools Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
progressreader Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
promise Move Go() promise-like func from utils to pkg/promise 2014-09-29 23:16:27 -07:00
proxy Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
pubsub Don't use time.After if there is no timeout 2015-07-14 09:14:51 -07:00
random Add global instance of *(math/rand).Rand and Reader 2015-07-28 22:30:57 -07:00
reexec make docker compile on freebsd 2015-07-29 21:25:56 +03:00
signal Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
sockets make docker compile on freebsd 2015-07-29 21:25:56 +03:00
stdcopy Fix Typo in stdcopy.go 2015-06-24 15:00:14 +08:00
streamformatter Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
stringid Add GenerateNonCryptoID function to avoid entropy exhaustion 2015-07-28 22:31:01 -07:00
stringutils Use global random *rand.Rand instance in pkg 2015-07-29 09:30:48 -07:00
symlink Remove subdirectories MAINTAINERS files 2015-03-06 18:21:51 -08:00
sysinfo make docker compile on freebsd 2015-07-29 21:25:56 +03:00
system make docker compile on freebsd 2015-07-29 21:25:56 +03:00
systemd Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
tailfile Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
tarsum Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
term Fix golint nit in term_windows.go 2015-07-27 17:40:49 -07:00
timeoutconn Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
timeutils Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
tlsconfig cli: new daemon command and new cli package 2015-07-23 19:44:46 -04:00
truncindex Replace GenerateRandomID with GenerateNonCryptoID 2015-07-28 22:31:01 -07:00
ulimit Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
units Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
urlutil Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
useragent Lint on pkg/* packages 2015-07-27 21:26:21 +02:00
version Fix minor typo 2015-03-25 00:46:22 +08:00
README.md Add README to pkg 2013-12-23 23:12:19 +00:00

pkg/ is a collection of utility packages used by the Docker project without being specific to its internals.

Utility packages are kept separate from the docker core codebase to keep it as small and concise as possible. If some utilities grow larger and their APIs stabilize, they may be moved to their own repository under the Docker organization, to facilitate re-use by other projects. However that is not the priority.

The directory pkg is named after the same directory in the camlistore project. Since Brad is a core Go maintainer, we thought it made sense to copy his methods for organizing Go code :) Thanks Brad!

Because utility packages are small and neatly separated from the rest of the codebase, they are a good place to start for aspiring maintainers and contributors. Get in touch if you want to help maintain them!