From 0bdb5bdc5fc289072e04035ff169bdcb9f243472 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 14 Jul 2015 16:50:16 -0700 Subject: [PATCH] Remove atomic package, not needed anymore --- pkg/atomic/atomic.go | 74 --------------------------------------- pkg/atomic/atomic_test.go | 58 ------------------------------ 2 files changed, 132 deletions(-) delete mode 100644 pkg/atomic/atomic.go delete mode 100644 pkg/atomic/atomic_test.go diff --git a/pkg/atomic/atomic.go b/pkg/atomic/atomic.go deleted file mode 100644 index 6b6368aa..00000000 --- a/pkg/atomic/atomic.go +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Minio Client (C) 2015 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// NOTE - Rename() not guaranteed to be atomic on all filesystems which are not fully POSIX compatible - -// Package atomic provides atomic file write semantics by leveraging Rename's() atomicity. -package atomic - -import ( - "io/ioutil" - "os" - "path/filepath" - - "github.com/minio/minio/pkg/iodine" -) - -// File container provided for atomic file writes -type File struct { - *os.File - file string -} - -// Close the file replacing, returns an error if any -func (f *File) Close() error { - // close the embedded fd - if err := f.File.Close(); err != nil { - return iodine.New(err, nil) - } - // atomic rename to final destination - if err := os.Rename(f.Name(), f.file); err != nil { - return iodine.New(err, nil) - } - return nil -} - -// CloseAndPurge removes the temp file, closes the transaction and returns an error if any -func (f *File) CloseAndPurge() error { - // close the embedded fd - if err := f.File.Close(); err != nil { - return iodine.New(err, nil) - } - if err := os.Remove(f.Name()); err != nil { - return err - } - return nil -} - -// FileCreate creates a new file at filePath for atomic writes -func FileCreate(filePath string) (*File, error) { - f, err := ioutil.TempFile(filepath.Dir(filePath), filepath.Base(filePath)) - if err != nil { - return nil, iodine.New(err, nil) - } - if err := os.Chmod(f.Name(), 0600); err != nil { - if err := os.Remove(f.Name()); err != nil { - return nil, iodine.New(err, nil) - } - return nil, iodine.New(err, nil) - } - return &File{File: f, file: filePath}, nil -} diff --git a/pkg/atomic/atomic_test.go b/pkg/atomic/atomic_test.go deleted file mode 100644 index 31871b75..00000000 --- a/pkg/atomic/atomic_test.go +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Minio Client (C) 2015 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package atomic - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - . "github.com/minio/check" -) - -func Test(t *testing.T) { TestingT(t) } - -type MySuite struct{} - -var _ = Suite(&MySuite{}) - -func (s *MySuite) TestAtomic(c *C) { - root, err := ioutil.TempDir("/tmp", "atomic-") - c.Assert(err, IsNil) - f, err := FileCreate(filepath.Join(root, "testfile")) - c.Assert(err, IsNil) - _, err = os.Stat(filepath.Join(root, "testfile")) - c.Assert(err, Not(IsNil)) - err = f.Close() - c.Assert(err, IsNil) - _, err = os.Stat(filepath.Join(root, "testfile")) - c.Assert(err, IsNil) -} - -func (s *MySuite) TestAtomicPurge(c *C) { - root, err := ioutil.TempDir("/tmp", "atomic-") - c.Assert(err, IsNil) - f, err := FileCreate(filepath.Join(root, "testfile")) - c.Assert(err, IsNil) - _, err = os.Stat(filepath.Join(root, "testfile")) - c.Assert(err, Not(IsNil)) - err = f.CloseAndPurge() - c.Assert(err, IsNil) - err = f.Close() - c.Assert(err, Not(IsNil)) -}