-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
222f2df
commit e300cb0
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cikupin/ntfs-wr/pkg" | ||
zlog "github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var unmount = &cobra.Command{ | ||
Use: "unmount", | ||
Short: "Unmount external disk partition", | ||
Long: "Unmount external disk partition", | ||
Example: "$ ntfs-wr unmount <volume_dir_name>", | ||
PreRun: func(*cobra.Command, []string) { | ||
if !pkg.IsMacOS() { | ||
zlog.Fatal().Msg("this binary runs only for MacOS") | ||
} | ||
|
||
if !pkg.IsRoot() { | ||
zlog.Fatal().Msg("this binary runs only on root user") | ||
} | ||
}, | ||
Run: func(c *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
zlog.Error().Msg("please supply volume dirname as an argument. exiting now...") | ||
return | ||
} | ||
|
||
dirName := args[0] | ||
if !pkg.IsVolumeExist(dirName) { | ||
zlog.Error(). | ||
Str("volume_dir", fmt.Sprintf("/Volumes/%s", dirName)). | ||
Msg("volume directory is not exist") | ||
return | ||
} | ||
|
||
err := pkg.UnmountDisk(dirName) | ||
if err != nil { | ||
zlog.Fatal().Err(err). | ||
Str("full_path", fmt.Sprintf("/Volumes/%s", dirName)). | ||
Msg("cannot unmount volume") | ||
return | ||
} | ||
|
||
err = pkg.RemoveVolumeDir(dirName) | ||
if err != nil { | ||
zlog.Warn(). | ||
Str("full_path", fmt.Sprintf("/Volumes/%s", dirName)). | ||
Msg("volume unmounted succesfully, but failed to remove temporary volume dir. you can manually delete it.") | ||
return | ||
} | ||
|
||
zlog.Info(). | ||
Str("full_path", fmt.Sprintf("/Volumes/%s", dirName)). | ||
Msg("volume unmounted succesfully") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters