• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package gitee_common
17
18import (
19	"github.com/sirupsen/logrus"
20	"os"
21	"sort"
22	"time"
23)
24
25func (m *Manager) getNewerFileFromDir(cur string, less func(files []os.DirEntry, i, j int) bool) string {
26	for {
27		files, err := os.ReadDir(m.ArchiveDir)
28		if err != nil {
29			logrus.Errorf("read dir %s err: %s", m.ArchiveDir, err)
30			time.Sleep(10 * time.Second)
31			continue
32		}
33		sort.Slice(files, func(i, j int) bool {
34			return less(files, i, j)
35		})
36		if len(files) != 0 {
37			f := files[len(files)-1]
38			if f.Name() != cur {
39				logrus.Infof("new package found, name: %s", f.Name())
40				return f.Name()
41			}
42		}
43		time.Sleep(10 * time.Second)
44	}
45}
46