Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
763122ae
Commit
763122ae
authored
Oct 29, 2017
by
Timothy St. Clair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update generated and dep addition of safefile
parent
ed4401c1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
472 additions
and
7 deletions
+472
-7
Godeps.json
Godeps/Godeps.json
+0
-0
LICENSES
Godeps/LICENSES
+34
-0
BUILD
pkg/kubelet/BUILD
+1
-0
BUILD
pkg/kubelet/checkpoint/BUILD
+42
-0
BUILD
pkg/kubelet/config/BUILD
+4
-7
BUILD
pkg/kubelet/pod/BUILD
+1
-0
BUILD
vendor/BUILD
+1
-0
.travis.yml
vendor/github.com/dchest/safefile/.travis.yml
+8
-0
BUILD
vendor/github.com/dchest/safefile/BUILD
+30
-0
LICENSE
vendor/github.com/dchest/safefile/LICENSE
+26
-0
README.md
vendor/github.com/dchest/safefile/README.md
+44
-0
appveyor.yml
vendor/github.com/dchest/safefile/appveyor.yml
+24
-0
rename.go
vendor/github.com/dchest/safefile/rename.go
+9
-0
rename_nonatomic.go
vendor/github.com/dchest/safefile/rename_nonatomic.go
+51
-0
safefile.go
vendor/github.com/dchest/safefile/safefile.go
+197
-0
No files found.
Godeps/Godeps.json
View file @
763122ae
This diff is collapsed.
Click to expand it.
Godeps/LICENSES
View file @
763122ae
...
...
@@ -29168,6 +29168,40 @@ SOFTWARE.
================================================================================
= vendor/github.com/dchest/safefile licensed under: =
Copyright (c) 2013 Dmitry Chestnykh <dmitry@codingrobots.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
= vendor/github.com/dchest/safefile/LICENSE 499ffd499356286ac590c21f7b8bd677
================================================================================
================================================================================
= vendor/github.com/dgrijalva/jwt-go licensed under: =
Copyright (c) 2012 Dave Grijalva
pkg/kubelet/BUILD
View file @
763122ae
...
...
@@ -254,6 +254,7 @@ filegroup(
"//pkg/kubelet/apis:all-srcs",
"//pkg/kubelet/cadvisor:all-srcs",
"//pkg/kubelet/certificate:all-srcs",
"//pkg/kubelet/checkpoint:all-srcs",
"//pkg/kubelet/client:all-srcs",
"//pkg/kubelet/cm:all-srcs",
"//pkg/kubelet/config:all-srcs",
...
...
pkg/kubelet/checkpoint/BUILD
0 → 100644
View file @
763122ae
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["checkpoint.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/checkpoint",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor/github.com/dchest/safefile:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["checkpoint_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/checkpoint",
library = ":go_default_library",
deps = [
"//pkg/apis/core:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
pkg/kubelet/config/BUILD
View file @
763122ae
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
...
...
@@ -26,6 +20,7 @@ go_library(
"//conditions:default": [],
}),
importpath = "k8s.io/kubernetes/pkg/kubelet/config",
visibility = ["//visibility:public"],
deps = [
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/core:go_default_library",
...
...
@@ -33,6 +28,7 @@ go_library(
"//pkg/apis/core/install:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//pkg/kubelet/checkpoint:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/events:go_default_library",
"//pkg/kubelet/types:go_default_library",
...
...
@@ -112,4 +108,5 @@ filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
pkg/kubelet/pod/BUILD
View file @
763122ae
...
...
@@ -14,6 +14,7 @@ go_library(
],
importpath = "k8s.io/kubernetes/pkg/kubelet/pod",
deps = [
"//pkg/kubelet/checkpoint:go_default_library",
"//pkg/kubelet/configmap:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/secret:go_default_library",
...
...
vendor/BUILD
View file @
763122ae
...
...
@@ -124,6 +124,7 @@ filegroup(
"//vendor/github.com/d2g/dhcp4client:all-srcs",
"//vendor/github.com/davecgh/go-spew/spew:all-srcs",
"//vendor/github.com/daviddengcn/go-colortext:all-srcs",
"//vendor/github.com/dchest/safefile:all-srcs",
"//vendor/github.com/dgrijalva/jwt-go:all-srcs",
"//vendor/github.com/docker/distribution/digestset:all-srcs",
"//vendor/github.com/docker/distribution/reference:all-srcs",
...
...
vendor/github.com/dchest/safefile/.travis.yml
0 → 100644
View file @
763122ae
language
:
go
go
:
-
1.1
-
1.2
-
1.3
-
1.4
-
tip
vendor/github.com/dchest/safefile/BUILD
0 → 100644
View file @
763122ae
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"rename.go",
"safefile.go",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"rename_nonatomic.go",
],
"//conditions:default": [],
}),
importpath = "github.com/dchest/safefile",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
vendor/github.com/dchest/safefile/LICENSE
0 → 100644
View file @
763122ae
Copyright (c) 2013 Dmitry Chestnykh <dmitry@codingrobots.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vendor/github.com/dchest/safefile/README.md
0 → 100644
View file @
763122ae
# safefile
[

](https://travis-ci.org/dchest/safefile)
[

](https://ci.appveyor.com/project/dchest/safefile)
Go package safefile implements safe "atomic" saving of files.
Instead of truncating and overwriting the destination file, it creates a
temporary file in the same directory, writes to it, and then renames the
temporary file to the original name when calling Commit.
### Installation
```
$ go get github.com/dchest/safefile
```
### Documentation
<https://godoc.org/github.com/dchest/safefile>
### Example
```
go
f
,
err
:=
safefile
.
Create
(
"/home/ken/report.txt"
,
0644
)
if
err
!=
nil
{
// ...
}
// Created temporary file /home/ken/sf-ppcyksu5hyw2mfec.tmp
defer
f
.
Close
()
_
,
err
=
io
.
WriteString
(
f
,
"Hello world"
)
if
err
!=
nil
{
// ...
}
// Wrote "Hello world" to /home/ken/sf-ppcyksu5hyw2mfec.tmp
err
=
f
.
Commit
()
if
err
!=
nil
{
// ...
}
// Renamed /home/ken/sf-ppcyksu5hyw2mfec.tmp to /home/ken/report.txt
```
vendor/github.com/dchest/safefile/appveyor.yml
0 → 100644
View file @
763122ae
version
:
"
{build}"
os
:
Windows Server 2012 R2
clone_folder
:
c:\projects\src\github.com\dchest\safefile
environment
:
PATH
:
c:\projects\bin;%PATH%
GOPATH
:
c:\projects
NOTIFY_TIMEOUT
:
5s
install
:
-
go version
-
go get golang.org/x/tools/cmd/vet
-
go get -v -t ./...
build_script
:
-
go tool vet -all .
-
go build ./...
-
go test -v -race ./...
test
:
off
deploy
:
off
vendor/github.com/dchest/safefile/rename.go
0 → 100644
View file @
763122ae
// +build !plan9,!windows windows,go1.5
package
safefile
import
"os"
func
rename
(
oldname
,
newname
string
)
error
{
return
os
.
Rename
(
oldname
,
newname
)
}
vendor/github.com/dchest/safefile/rename_nonatomic.go
0 → 100644
View file @
763122ae
// +build plan9 windows,!go1.5
// os.Rename on Windows before Go 1.5 and Plan 9 will not overwrite existing
// files, thus we cannot guarantee atomic saving of file by doing rename.
// We will have to do some voodoo to minimize data loss on those systems.
package
safefile
import
(
"os"
"path/filepath"
)
func
rename
(
oldname
,
newname
string
)
error
{
err
:=
os
.
Rename
(
oldname
,
newname
)
if
err
!=
nil
{
// If newname exists ("original"), we will try renaming it to a
// new temporary name, then renaming oldname to the newname,
// and deleting the renamed original. If system crashes between
// renaming and deleting, the original file will still be available
// under the temporary name, so users can manually recover data.
// (No automatic recovery is possible because after crash the
// temporary name is not known.)
var
origtmp
string
for
{
origtmp
,
err
=
makeTempName
(
newname
,
filepath
.
Base
(
newname
))
if
err
!=
nil
{
return
err
}
_
,
err
=
os
.
Stat
(
origtmp
)
if
err
==
nil
{
continue
// most likely will never happen
}
break
}
err
=
os
.
Rename
(
newname
,
origtmp
)
if
err
!=
nil
{
return
err
}
err
=
os
.
Rename
(
oldname
,
newname
)
if
err
!=
nil
{
// Rename still fails, try to revert original rename,
// ignoring errors.
os
.
Rename
(
origtmp
,
newname
)
return
err
}
// Rename succeeded, now delete original file.
os
.
Remove
(
origtmp
)
}
return
nil
}
vendor/github.com/dchest/safefile/safefile.go
0 → 100644
View file @
763122ae
// Copyright 2013 Dmitry Chestnykh. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package safefile implements safe "atomic" saving of files.
//
// Instead of truncating and overwriting the destination file, it creates a
// temporary file in the same directory, writes to it, and then renames the
// temporary file to the original name when calling Commit.
//
// Example:
//
// f, err := safefile.Create("/home/ken/report.txt", 0644)
// if err != nil {
// // ...
// }
// // Created temporary file /home/ken/sf-ppcyksu5hyw2mfec.tmp
//
// defer f.Close()
//
// _, err = io.WriteString(f, "Hello world")
// if err != nil {
// // ...
// }
// // Wrote "Hello world" to /home/ken/sf-ppcyksu5hyw2mfec.tmp
//
// err = f.Commit()
// if err != nil {
// // ...
// }
// // Renamed /home/ken/sf-ppcyksu5hyw2mfec.tmp to /home/ken/report.txt
//
package
safefile
import
(
"crypto/rand"
"encoding/base32"
"errors"
"io"
"os"
"path/filepath"
"strings"
)
// ErrAlreadyCommitted error is returned when calling Commit on a file that
// has been already successfully committed.
var
ErrAlreadyCommitted
=
errors
.
New
(
"file already committed"
)
type
File
struct
{
*
os
.
File
origName
string
closeFunc
func
(
*
File
)
error
isClosed
bool
// if true, temporary file has been closed, but not renamed
isCommitted
bool
// if true, the file has been successfully committed
}
func
makeTempName
(
origname
,
prefix
string
)
(
tempname
string
,
err
error
)
{
origname
=
filepath
.
Clean
(
origname
)
if
len
(
origname
)
==
0
||
origname
[
len
(
origname
)
-
1
]
==
filepath
.
Separator
{
return
""
,
os
.
ErrInvalid
}
// Generate 10 random bytes.
// This gives 80 bits of entropy, good enough
// for making temporary file name unpredictable.
var
rnd
[
10
]
byte
if
_
,
err
:=
rand
.
Read
(
rnd
[
:
]);
err
!=
nil
{
return
""
,
err
}
name
:=
prefix
+
"-"
+
strings
.
ToLower
(
base32
.
StdEncoding
.
EncodeToString
(
rnd
[
:
]))
+
".tmp"
return
filepath
.
Join
(
filepath
.
Dir
(
origname
),
name
),
nil
}
// Create creates a temporary file in the same directory as filename,
// which will be renamed to the given filename when calling Commit.
func
Create
(
filename
string
,
perm
os
.
FileMode
)
(
*
File
,
error
)
{
for
{
tempname
,
err
:=
makeTempName
(
filename
,
"sf"
)
if
err
!=
nil
{
return
nil
,
err
}
f
,
err
:=
os
.
OpenFile
(
tempname
,
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_EXCL
,
perm
)
if
err
!=
nil
{
if
os
.
IsExist
(
err
)
{
continue
}
return
nil
,
err
}
return
&
File
{
File
:
f
,
origName
:
filename
,
closeFunc
:
closeUncommitted
,
},
nil
}
}
// OrigName returns the original filename given to Create.
func
(
f
*
File
)
OrigName
()
string
{
return
f
.
origName
}
// Close closes temporary file and removes it.
// If the file has been committed, Close is no-op.
func
(
f
*
File
)
Close
()
error
{
return
f
.
closeFunc
(
f
)
}
func
closeUncommitted
(
f
*
File
)
error
{
err0
:=
f
.
File
.
Close
()
err1
:=
os
.
Remove
(
f
.
Name
())
f
.
closeFunc
=
closeAgainError
if
err0
!=
nil
{
return
err0
}
return
err1
}
func
closeAfterFailedRename
(
f
*
File
)
error
{
// Remove temporary file.
//
// The note from Commit function applies here too, as we may be
// removing a different file. However, since we rely on our temporary
// names being unpredictable, this should not be a concern.
f
.
closeFunc
=
closeAgainError
return
os
.
Remove
(
f
.
Name
())
}
func
closeCommitted
(
f
*
File
)
error
{
// noop
return
nil
}
func
closeAgainError
(
f
*
File
)
error
{
return
os
.
ErrInvalid
}
// Commit safely commits data into the original file by syncing temporary
// file to disk, closing it and renaming to the original file name.
//
// In case of success, the temporary file is closed and no longer exists
// on disk. It is safe to call Close after Commit: the operation will do
// nothing.
//
// In case of error, the temporary file is still opened and exists on disk;
// it must be closed by callers by calling Close or by trying to commit again.
// Note that when trying to Commit again after a failed Commit when the file
// has been closed, but not renamed to its original name (the new commit will
// try again to rename it), safefile cannot guarantee that the temporary file
// has not been changed, or that it is the same temporary file we were dealing
// with. However, since the temporary name is unpredictable, it is unlikely
// that this happened accidentally. If complete atomicity is needed, do not
// Commit again after error, write the file again.
func
(
f
*
File
)
Commit
()
error
{
if
f
.
isCommitted
{
return
ErrAlreadyCommitted
}
if
!
f
.
isClosed
{
// Sync to disk.
err
:=
f
.
Sync
()
if
err
!=
nil
{
return
err
}
// Close underlying os.File.
err
=
f
.
File
.
Close
()
if
err
!=
nil
{
return
err
}
f
.
isClosed
=
true
}
// Rename.
err
:=
rename
(
f
.
Name
(),
f
.
origName
)
if
err
!=
nil
{
f
.
closeFunc
=
closeAfterFailedRename
return
err
}
f
.
closeFunc
=
closeCommitted
f
.
isCommitted
=
true
return
nil
}
// WriteFile is a safe analog of ioutil.WriteFile.
func
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
f
,
err
:=
Create
(
filename
,
perm
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
n
,
err
:=
f
.
Write
(
data
)
if
err
!=
nil
{
return
err
}
if
err
==
nil
&&
n
<
len
(
data
)
{
err
=
io
.
ErrShortWrite
return
err
}
return
f
.
Commit
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment