// Copyright 2015 The etcd Authors//// 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 fileutilimport ()func ( string, string, uint, time.Duration, <-chanstruct{}) <-chanerror {returnpurgeFile(, , , , , nil, nil)}func ( string, string, uint, time.Duration, <-chanstruct{}) (<-chanstruct{}, <-chanerror) { := make(chanstruct{}) := purgeFile(, , , , , nil, )return , }// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil.// if donec is non-nil, the function closes it to notify its exit.func purgeFile( string, string, uint, time.Duration, <-chanstruct{}, chan<- string, chan<- struct{}) <-chanerror { := make(chanerror, 1)gofunc() {if != nil {deferclose() }for { , := ReadDir()if != nil { <- return } := make([]string, 0)for , := range {ifstrings.HasSuffix(, ) { = append(, ) } }sort.Strings() = forlen() > int() { := filepath.Join(, [0]) , := TryLockFile(, os.O_WRONLY, PrivateFileMode)if != nil {break }if = os.Remove(); != nil { <- return }if = .Close(); != nil {plog.Errorf("error unlocking %s when purging file (%v)", .Name(), ) <- return }plog.Infof("purged file %s successfully", ) = [1:] }if != nil {for := 0; < len()-len(); ++ { <- [] } }select {case<-time.After():case<-:return } } }()return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.