Skip to content

Commit

Permalink
Support Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Apr 29, 2020
1 parent 6a63cc2 commit 9fc0ceb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func TestServerClientObjectAttrsAfterOverwriteWithVersioning(t *testing.T) {
t.Logf("checking initial object attributes")
checkObjectAttrs(initialObj, originalObjAttrs, t)

// sleep for at least 100ns or more, so the creation time will differ on all platforms.
time.Sleep(time.Microsecond)

latestObjVersion := Object{BucketName: bucketName, Name: "img/low-res/party-01.jpg", Content: []byte(content2), ContentType: contentType, Crc32c: encodedChecksum(uint32ToBytes(uint32Checksum([]byte(content2)))), Md5Hash: encodedHash(md5Hash([]byte(content2)))}
server.CreateObject(latestObjVersion)
objHandle = client.Bucket(bucketName).Object(latestObjVersion.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestBucketCreateGetList(t *testing.T) {
}
timeBeforeCreation := time.Now().Truncate(time.Second) // we may lose precission
err = storage.CreateBucket(bucket.Name, bucket.VersioningEnabled)
timeAfterCreation := time.Now()
timeAfterCreation := time.Now().Add(time.Microsecond)
if reflect.TypeOf(storage) == reflect.TypeOf(&storageFS{}) && bucket.VersioningEnabled {
if err == nil {
t.Fatal("fs storage should not accept creating buckets with versioning, but it's not failing")
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *storageFS) ListObjects(bucketName string, versions bool) ([]Object, err
}
objects := []Object{}
for _, info := range infos {
unescaped, err := url.PathUnescape(info.Name())
unescaped, err := url.PathUnescape(filepath.ToSlash(info.Name()))
if err != nil {
return nil, fmt.Errorf("failed to unescape object name %s: %w", info.Name(), err)
}
Expand Down
18 changes: 18 additions & 0 deletions internal/backend/time_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2019 Francisco Souza. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package backend

import (
"os"
"syscall"
)

func createTimeFromFileInfo(input os.FileInfo) syscall.Timespec {
if statT, ok := input.Sys().(*syscall.Win32FileAttributeData); ok {
nsec := statT.CreationTime.Nanoseconds()
return syscall.NsecToTimespec(nsec)
}
return syscall.Timespec{}
}
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/fsouza/fake-gcs-server/fakestorage"
Expand Down Expand Up @@ -83,7 +82,9 @@ func objectsFromBucket(localBucketPath, bucketName string) ([]fakestorage.Object
var objects []fakestorage.Object
err := filepath.Walk(localBucketPath, func(path string, info os.FileInfo, _ error) error {
if info.Mode().IsRegular() {
objectKey := strings.TrimLeft(strings.Replace(path, localBucketPath, "", 1), "/")
// Rel() should never return error since path always descend from localBucketPath
relPath, _ := filepath.Rel(localBucketPath, path)
objectKey := filepath.ToSlash(relPath)
fileContent, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("could not read file %q: %w", path, err)
Expand Down

0 comments on commit 9fc0ceb

Please sign in to comment.