New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow modtime zero value #40

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@ghostsquad

ghostsquad commented Dec 25, 2017

This prevents the vfsdata.go file from changing if the only
thing that has changed is the file modtime.

Resolves #26

Allow modtime zero value
This prevents the vfsdata.go file from changing if the only
thing that has changed is the file modtime.

Resolves #26
@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur

dmitshur Jan 4, 2018

Member

Sorry about the delay.

Thank you for the PR, but I prefer not to merge this. I think this functionality can and should be achieved orthogonally—it doesn't need to be built into vfsgen.

More specifically, it can be achieved by creating a passthrough http.FileSystem wrapper implementation, one that makes no changes to the input filesystem, except it strips all modtimes to be zero:

// ZeroModTimeFileSystem is an http.FileSystem wrapper.
// It exposes a filesystem exactly like Source, except
// all file modification times are changed to zero.
type ZeroModTimeFileSystem struct {
	Source http.FileSystem
}

func (fs ZeroModTimeFileSystem) Open(name string) (http.File, error) {
	f, err := fs.Source.Open(name)
	return file{f}, err
}

type file struct {
	http.File
}

func (f file) Stat() (os.FileInfo, error) {
	fi, err := f.File.Stat()
	return fileInfo{fi}, err
}

type fileInfo struct {
	os.FileInfo
}

func (fi fileInfo) ModTime() time.Time { return time.Time{} }
Member

dmitshur commented Jan 4, 2018

Sorry about the delay.

Thank you for the PR, but I prefer not to merge this. I think this functionality can and should be achieved orthogonally—it doesn't need to be built into vfsgen.

More specifically, it can be achieved by creating a passthrough http.FileSystem wrapper implementation, one that makes no changes to the input filesystem, except it strips all modtimes to be zero:

// ZeroModTimeFileSystem is an http.FileSystem wrapper.
// It exposes a filesystem exactly like Source, except
// all file modification times are changed to zero.
type ZeroModTimeFileSystem struct {
	Source http.FileSystem
}

func (fs ZeroModTimeFileSystem) Open(name string) (http.File, error) {
	f, err := fs.Source.Open(name)
	return file{f}, err
}

type file struct {
	http.File
}

func (f file) Stat() (os.FileInfo, error) {
	fi, err := f.File.Stat()
	return fileInfo{fi}, err
}

type fileInfo struct {
	os.FileInfo
}

func (fi fileInfo) ModTime() time.Time { return time.Time{} }

@dmitshur dmitshur closed this Jan 4, 2018

@ghostsquad

This comment has been minimized.

Show comment
Hide comment
@ghostsquad

ghostsquad Jan 5, 2018

ghostsquad commented Jan 5, 2018

@ghostsquad ghostsquad deleted the ghostsquad:feature/allow-for-zero-modtime branch Jan 5, 2018

@dmitshur dmitshur referenced this pull request Sep 18, 2018

Closed

Make the mod time optional #54

@dmitshur dmitshur referenced this pull request Sep 26, 2018

Closed

ModTime option #58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment