@@ -2,7 +2,7 @@ package cmd
22
33import (
44 "context"
5- "crypto/md5"
5+ "crypto/md5" // #nosec G501 -- Drive API exposes MD5 checksums; used only for sync change detection.
66 "encoding/hex"
77 "encoding/json"
88 "errors"
@@ -67,8 +67,8 @@ func (c *DriveSyncPullCmd) Run(ctx context.Context, flags *RootFlags) error {
6767 if cfg .FolderID == "" || rootPath == "" {
6868 return usage ("missing --folder or --out (or state file)" )
6969 }
70- if err := os .MkdirAll (rootPath , 0o755 ); err != nil {
71- return err
70+ if mkdirErr := os .MkdirAll (rootPath , 0o750 ); mkdirErr != nil {
71+ return mkdirErr
7272 }
7373
7474 svc , err := newDriveService (ctx , account )
@@ -234,7 +234,7 @@ func loadDriveSyncConfig(statePath string, rootPath string, direction string, ac
234234 return "" , rootPath , cfg , nil
235235 }
236236
237- if data , err := os .ReadFile (statePath ); err == nil {
237+ if data , err := os .ReadFile (statePath ); err == nil { //nolint:gosec // state path is explicit CLI input or derived from local sync root
238238 var stored driveSyncConfig
239239 if jsonErr := json .Unmarshal (data , & stored ); jsonErr == nil {
240240 if cfg .FolderID == "" {
@@ -271,8 +271,8 @@ func resolveDriveSyncStatePath(explicit string, rootPath string) (string, error)
271271 return filepath .Join (rootPath , driveSyncStateFile ), nil
272272}
273273
274- func saveDriveSyncState (path string , cfg driveSyncConfig ) error {
275- if path == "" {
274+ func saveDriveSyncState (statePath string , cfg driveSyncConfig ) error {
275+ if statePath == "" {
276276 return nil
277277 }
278278 cfg .Version = driveSyncVersion
@@ -284,7 +284,7 @@ func saveDriveSyncState(path string, cfg driveSyncConfig) error {
284284 }
285285 data = append (data , '\n' )
286286
287- if err := os .WriteFile (path , data , 0o600 ); err != nil {
287+ if err := os .WriteFile (statePath , data , 0o600 ); err != nil {
288288 return fmt .Errorf ("write sync state: %w" , err )
289289 }
290290 return nil
@@ -308,13 +308,13 @@ func splitDriveItems(items []driveTreeItem, exportDocs bool) (map[string]driveTr
308308 folders [it .Path ] = it
309309 continue
310310 }
311- path := it .Path
311+ relPath := it .Path
312312 if exportDocs && strings .HasPrefix (it .MimeType , "application/vnd.google-apps." ) {
313313 exportExt := driveExportExtension (driveExportMimeType (it .MimeType ))
314- path = replaceExt (path , exportExt )
314+ relPath = replaceExt (relPath , exportExt )
315315 }
316- it .Path = path
317- files [path ] = it
316+ it .Path = relPath
317+ files [relPath ] = it
318318 }
319319 return files , folders
320320}
@@ -432,8 +432,8 @@ func ensureDriveSyncExcludes(excludes []string) []string {
432432 return out
433433}
434434
435- func fileMD5 (path string ) (string , error ) {
436- f , err := os .Open (path ) //nolint:gosec // user-provided path
435+ func fileMD5 (filePath string ) (string , error ) {
436+ f , err := os .Open (filePath ) //nolint:gosec // user-provided path
437437 if err != nil {
438438 return "" , err
439439 }
@@ -585,9 +585,9 @@ func ensurePlanDirs(plan *driveSyncPlan, dir string, actionType string) {
585585 }
586586}
587587
588- func hasAction (actions []driveSyncAction , actionType string , path string ) bool {
588+ func hasAction (actions []driveSyncAction , actionType string , actionPath string ) bool {
589589 for _ , a := range actions {
590- if a .Type == actionType && a .Path == path {
590+ if a .Type == actionType && a .Path == actionPath {
591591 return true
592592 }
593593 }
@@ -596,10 +596,7 @@ func hasAction(actions []driveSyncAction, actionType string, path string) bool {
596596
597597func needsPull (remote driveTreeItem , local localFileInfo , checksum bool ) bool {
598598 if checksum && remote .MD5 != "" && local .MD5 != "" {
599- if remote .MD5 != local .MD5 {
600- return true
601- }
602- return false
599+ return remote .MD5 != local .MD5
603600 }
604601 if remote .Size > 0 && remote .Size != local .Size {
605602 return true
@@ -616,10 +613,7 @@ func needsPush(remote driveTreeItem, local localFileInfo, checksum bool) bool {
616613 return false
617614 }
618615 if checksum && remote .MD5 != "" && local .MD5 != "" {
619- if remote .MD5 != local .MD5 {
620- return true
621- }
622- return false
616+ return remote .MD5 != local .MD5
623617 }
624618 if remote .Size > 0 && remote .Size != local .Size {
625619 return true
@@ -673,7 +667,7 @@ func applyDrivePullPlan(ctx context.Context, svc *drive.Service, rootPath string
673667 continue
674668 }
675669 dir := filepath .Join (rootPath , filepath .FromSlash (action .Path ))
676- if err := os .MkdirAll (dir , 0o755 ); err != nil {
670+ if err := os .MkdirAll (dir , 0o750 ); err != nil {
677671 return err
678672 }
679673 }
0 commit comments