From 8ac48bbda592328d9a49ee61195db270a5e5d3db Mon Sep 17 00:00:00 2001 From: tickstep Date: Thu, 16 Jun 2022 22:30:12 +0800 Subject: [PATCH] fix file & folder perm eror --- internal/command/sync.go | 2 +- internal/config/pan_config.go | 4 ++-- internal/functions/panupload/sync_database_bolt.go | 8 ++++---- internal/syncdrive/bolt_db.go | 2 +- internal/syncdrive/file_action_task.go | 2 +- internal/syncdrive/sync_task.go | 6 +++--- internal/syncdrive/sync_task_mgr.go | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/command/sync.go b/internal/command/sync.go index 91baf0f..4d8f965 100644 --- a/internal/command/sync.go +++ b/internal/command/sync.go @@ -173,7 +173,7 @@ func RunSync(fileDownloadParallel, fileUploadParallel int, downloadBlockSize, up syncFolderRootPath := config.GetSyncDriveDir() if b, e := utils.PathExists(syncFolderRootPath); e == nil { if !b { - os.MkdirAll(syncFolderRootPath, 0600) + os.MkdirAll(syncFolderRootPath, 0755) } } diff --git a/internal/config/pan_config.go b/internal/config/pan_config.go index fd02e3d..86db8e1 100644 --- a/internal/config/pan_config.go +++ b/internal/config/pan_config.go @@ -195,8 +195,8 @@ func (c *PanConfig) lazyOpenConfigFile() (err error) { } c.fileMu.Lock() - os.MkdirAll(filepath.Dir(c.configFilePath), 0700) - c.configFile, err = os.OpenFile(c.configFilePath, os.O_CREATE|os.O_RDWR, 0600) + os.MkdirAll(filepath.Dir(c.configFilePath), 0755) + c.configFile, err = os.OpenFile(c.configFilePath, os.O_CREATE|os.O_RDWR, 0755) c.fileMu.Unlock() if err != nil { diff --git a/internal/functions/panupload/sync_database_bolt.go b/internal/functions/panupload/sync_database_bolt.go index b7a69e0..d82175d 100644 --- a/internal/functions/panupload/sync_database_bolt.go +++ b/internal/functions/panupload/sync_database_bolt.go @@ -41,7 +41,7 @@ type boltKV struct { } func openBoltDb(file string, bucket string) (SyncDb, error) { - db, err := bolt.Open(file + "_bolt.db", 0600, &bolt.Options{Timeout: 5 * time.Second}) + db, err := bolt.Open(file+"_bolt.db", 0755, &bolt.Options{Timeout: 5 * time.Second}) if err != nil { return nil, err @@ -138,7 +138,7 @@ func (db *boltDB) First(prefix string) (*UploadedFileMeta, error) { func (db *boltDB) Next(prefix string) (*UploadedFileMeta, error) { data := &UploadedFileMeta{} - if _,ok := db.next[prefix]; ok { + if _, ok := db.next[prefix]; ok { if db.next[prefix].off >= db.next[prefix].size { return nil, fmt.Errorf("no any more record") } @@ -165,7 +165,7 @@ func (db *boltDB) Put(key string, value *UploadedFileMeta) error { } b := tx.Bucket([]byte(db.bucket)) if b == nil { - b,err = tx.CreateBucket([]byte(db.bucket)) + b, err = tx.CreateBucket([]byte(db.bucket)) if err != nil { return err } @@ -182,4 +182,4 @@ func (db *boltDB) Close() error { return db.db.Close() } return nil -} \ No newline at end of file +} diff --git a/internal/syncdrive/bolt_db.go b/internal/syncdrive/bolt_db.go index bfbb701..b61b625 100644 --- a/internal/syncdrive/bolt_db.go +++ b/internal/syncdrive/bolt_db.go @@ -36,7 +36,7 @@ func NewBoltDb(dbFilePath string) *BoltDb { } func (b *BoltDb) Open() (bool, error) { - db, err := bolt.Open(b.Path, 0600, &bolt.Options{Timeout: 5 * time.Second}) + db, err := bolt.Open(b.Path, 0755, &bolt.Options{Timeout: 5 * time.Second}) if err != nil { return false, err } diff --git a/internal/syncdrive/file_action_task.go b/internal/syncdrive/file_action_task.go index 30922f5..bdd4055 100644 --- a/internal/syncdrive/file_action_task.go +++ b/internal/syncdrive/file_action_task.go @@ -176,7 +176,7 @@ func (f *FileActionTask) downloadFile(ctx context.Context) error { } localDir := path.Dir(f.syncItem.getLocalFileFullPath()) if b, e := utils.PathExists(localDir); e == nil && !b { - os.MkdirAll(localDir, 0600) + os.MkdirAll(localDir, 0755) time.Sleep(200 * time.Millisecond) } writer, file, err := downloader.NewDownloaderWriterByFilename(f.syncItem.getLocalFileDownloadingFullPath(), os.O_CREATE|os.O_WRONLY, 0666) diff --git a/internal/syncdrive/sync_task.go b/internal/syncdrive/sync_task.go index 6a48a11..11b9d1d 100644 --- a/internal/syncdrive/sync_task.go +++ b/internal/syncdrive/sync_task.go @@ -179,7 +179,7 @@ func (t *SyncTask) Stop() error { func (t *SyncTask) panSyncDbFullPath() string { dir := path.Join(t.syncDbFolderPath, t.Id) if b, _ := utils.PathExists(dir); !b { - os.MkdirAll(dir, 0600) + os.MkdirAll(dir, 0755) } return path.Join(dir, "pan.bolt") } @@ -188,7 +188,7 @@ func (t *SyncTask) panSyncDbFullPath() string { func (t *SyncTask) localSyncDbFullPath() string { dir := path.Join(t.syncDbFolderPath, t.Id) if b, _ := utils.PathExists(dir); !b { - os.MkdirAll(dir, 0600) + os.MkdirAll(dir, 0755) } return path.Join(dir, "local.bolt") } @@ -197,7 +197,7 @@ func (t *SyncTask) localSyncDbFullPath() string { func (t *SyncTask) syncFileDbFullPath() string { dir := path.Join(t.syncDbFolderPath, t.Id) if b, _ := utils.PathExists(dir); !b { - os.MkdirAll(dir, 0600) + os.MkdirAll(dir, 0755) } return path.Join(dir, "sync.bolt") } diff --git a/internal/syncdrive/sync_task_mgr.go b/internal/syncdrive/sync_task_mgr.go index 86cc131..71ed403 100644 --- a/internal/syncdrive/sync_task_mgr.go +++ b/internal/syncdrive/sync_task_mgr.go @@ -89,7 +89,7 @@ func (m *SyncTaskManager) parseConfigFile() error { if b, _ := utils.PathExists(configFilePath); b != true { //text := utils.ObjectToJsonStr(r, true) - //ioutil.WriteFile(ConfigFilePath, []byte(text), 0600) + //ioutil.WriteFile(ConfigFilePath, []byte(text), 0755) return fmt.Errorf("备份配置文件不存在:" + m.ConfigFilePath()) } data, e := ioutil.ReadFile(configFilePath) @@ -145,7 +145,7 @@ func (m *SyncTaskManager) Start() (bool, error) { time.Sleep(200 * time.Millisecond) } // save config file - ioutil.WriteFile(m.ConfigFilePath(), []byte(utils.ObjectToJsonStr(m.syncDriveConfig, true)), 0600) + ioutil.WriteFile(m.ConfigFilePath(), []byte(utils.ObjectToJsonStr(m.syncDriveConfig, true)), 0755) return true, nil } @@ -162,6 +162,6 @@ func (m *SyncTaskManager) Stop() (bool, error) { } // save config file - ioutil.WriteFile(m.ConfigFilePath(), []byte(utils.ObjectToJsonStr(m.syncDriveConfig, true)), 0600) + ioutil.WriteFile(m.ConfigFilePath(), []byte(utils.ObjectToJsonStr(m.syncDriveConfig, true)), 0755) return true, nil }