@@ -71,12 +71,13 @@ func (c Command) Run(ctx context.Context) error {
7171 }
7272
7373 destInfo , err := os .Stat (c .Destination )
74- if err == nil {
74+ switch {
75+ case err == nil :
7576 // Destination exists - check if it's an empty directory
7677 if ! destInfo .IsDir () {
7778 return errors .E (op , errors .Exist , types .UniquePath (c .Destination ), fmt .Errorf ("destination exists and is not a directory" ))
7879 }
79-
80+
8081 // Check if directory is empty
8182 entries , err := os .ReadDir (c .Destination )
8283 if err != nil {
@@ -86,14 +87,14 @@ func (c Command) Run(ctx context.Context) error {
8687 return errors .E (op , errors .Exist , types .UniquePath (c .Destination ), fmt .Errorf ("destination directory already exists" ))
8788 }
8889 // Directory exists but is empty, we can use it
89- } else if ! goerrors .Is (err , os .ErrNotExist ) {
90- return errors .E (op , errors .IO , types .UniquePath (c .Destination ), err )
91- } else {
90+ case goerrors .Is (err , os .ErrNotExist ):
9291 // Directory doesn't exist, create it
9392 err = os .MkdirAll (c .Destination , 0700 )
9493 if err != nil {
9594 return errors .E (op , errors .IO , types .UniquePath (c .Destination ), err )
9695 }
96+ default :
97+ return errors .E (op , errors .IO , types .UniquePath (c .Destination ), err )
9798 }
9899
99100 // normalize path to a filepath
0 commit comments