~sircmpwn/sr.ht-dev

go-git: storage/filesystem/dotgit: Fix file permissions v1 APPLIED

Adnan Maolood: 1
 storage/filesystem/dotgit: Fix file permissions

 1 files changed, 32 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/36771/mbox | git am -3
Learn more about email & git

[PATCH go-git] storage/filesystem/dotgit: Fix file permissions Export this patch

When using the osfs backend, packfiles are created with 0600 permissions
instead of 0644. This is due to the behavior of osfs.OS.TempFile, which
calls out to ioutil.TempFile. osfs does not provide a chmod abstraction,
so we cannot change the permissions of the temporary file. Instead,
create a new file with the proper permissions and copy the temporary
file into it.
---
This should fix the issues with repositories cloned with go-git.
Will follow up with a pull request for upstream later.

 storage/filesystem/dotgit/writers.go | 34 ++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/storage/filesystem/dotgit/writers.go b/storage/filesystem/dotgit/writers.go
index e2ede93..3f6ab96 100644
--- a/storage/filesystem/dotgit/writers.go
+++ b/storage/filesystem/dotgit/writers.go
@@ -143,7 +143,7 @@ func (w *PackWriter) save() error {
		return err
	}

	return w.fs.Rename(w.fw.Name(), fmt.Sprintf("%s.pack", base))
	return renameFile(w.fs, w.fw.Name(), fmt.Sprintf("%s.pack", base))
}

func (w *PackWriter) encodeIdx(writer io.Writer) error {
@@ -280,5 +280,35 @@ func (w *ObjectWriter) save() error {
	hash := w.Hash().String()
	file := w.fs.Join(objectsPath, hash[0:2], hash[2:40])

	return w.fs.Rename(w.f.Name(), file)
	return renameFile(w.fs, w.f.Name(), file)
}

func renameFile(fs billy.Filesystem, tmpPath string, dstPath string) error {
	// We can't simply use fs.Rename here since TempFile creates a file with
	// 0600 permissions. Instead, create a new file with 0644 permissions and
	// copy from the temporary file.
	tmp, err := fs.Open(tmpPath)
	if err != nil {
		return err
	}
	defer tmp.Close()

	dst, err := fs.Create(dstPath)
	if err != nil {
		return err
	}
	if _, err := io.Copy(dst, tmp); err != nil {
		return err
	}
	if err := dst.Close(); err != nil {
		return err
	}

	if err := tmp.Close(); err != nil {
		return err
	}
	if err := fs.Remove(tmp.Name()); err != nil {
		return err
	}
	return nil
}

base-commit: 70373b908e0ad26e611d8edb9822aa14c6f080d5
-- 
2.38.1
Pushed to our fork's sourcehut branch. Will need follow-up patch to
update git.sr.ht.

Thanks!