From a4d557cf500e4956ae8f759460422db278bd9764 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 23 Jul 2026 12:23:23 +0200 Subject: [PATCH] user: align Windows mkdir behavior with Unix The Windows implementation of mkdirAs was originally introduced as a minimal wrapper around os.MkdirAll because ownership is not supported on Windows and the uid/gid parameters were only needed to keep the daemon starting. As a result, MkdirAndChown would also create missing parent directories, unlike the Unix implementation. Use os.Mkdir when mkAll is false to preserve the documented semantics, while retaining the simplified Windows implementation for ownership and permissions. Originally introduced in [moby/moby@bfe252b78184][1], which added a Windows-specific implementation to work around limitations on that platform; > A recent change to use pkg\idtools causes a chown to be on the > startup path of the daemon. Chown is not supported on Windows, > hence the daemon would not start. [1]: https://github.com/moby/moby/commit/bfe252b78184d22d74a555a82aafc9e6dae3babc Signed-off-by: Sebastiaan van Stijn --- user/idtools_windows.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/user/idtools_windows.go b/user/idtools_windows.go index 9de730ca..5fd7f45b 100644 --- a/user/idtools_windows.go +++ b/user/idtools_windows.go @@ -1,13 +1,17 @@ package user -import ( - "os" -) +import "os" -// This is currently a wrapper around [os.MkdirAll] since currently -// permissions aren't set through this path, the identity isn't utilized. -// Ownership is handled elsewhere, but in the future could be support here -// too. -func mkdirAs(path string, _ os.FileMode, _, _ int, _, _ bool) error { - return os.MkdirAll(path, 0) +// mkdirAs creates path, optionally creating any missing parent directories. +// +// On Windows this is currently a thin wrapper around os.Mkdir and +// os.MkdirAll. Unlike the Unix implementation, ownership and permission +// bits are not applied, and errors for existing paths follow the underlying +// os package semantics (for example, an existing non-directory does not +// return ENOTDIR). +func mkdirAs(path string, _ os.FileMode, _, _ int, mkAll, _ bool) error { + if mkAll { + return os.MkdirAll(path, 0) + } + return os.Mkdir(path, 0) }