Commit 6eeca1f8 authored by Kirill Unitsaev's avatar Kirill Unitsaev

preset/files: use config.OpStatus instead of local constants

parent d4a24afc
......@@ -5,10 +5,10 @@ import (
"os/exec"
"path/filepath"
"strings"
"ximperconf/config"
)
type opKind string
type opStatus string
const (
OpCopy opKind = "copy"
......@@ -16,13 +16,6 @@ const (
OpReplace opKind = "replace"
)
const (
StatusDone opStatus = "done"
StatusSkipped opStatus = "skipped"
StatusDryRun opStatus = "dry-run"
StatusError opStatus = "error"
)
type opOptions struct {
DryRun bool
Force bool
......@@ -30,7 +23,7 @@ type opOptions struct {
type opResult struct {
Kind opKind
Status opStatus
Status config.ItemStatus
Source string
Target string
Reason string
......@@ -47,7 +40,7 @@ func copyIfMissing(src, dest string, opts opOptions) opResult {
if err != nil {
return opResult{
Kind: OpCopy,
Status: StatusError,
Status: config.OpStatus.Error,
Source: src,
Target: dest,
Reason: err.Error(),
......@@ -57,7 +50,7 @@ func copyIfMissing(src, dest string, opts opOptions) opResult {
if _, err := os.Stat(dest); err == nil {
return opResult{
Kind: OpCopy,
Status: StatusSkipped,
Status: config.OpStatus.Skipped,
Target: dest,
Reason: "already exists",
}
......@@ -66,7 +59,7 @@ func copyIfMissing(src, dest string, opts opOptions) opResult {
if opts.DryRun {
return opResult{
Kind: OpCopy,
Status: StatusDryRun,
Status: config.OpStatus.DryRun,
Source: src,
Target: dest,
}
......@@ -81,7 +74,7 @@ func copyIfMissing(src, dest string, opts opOptions) opResult {
if err != nil {
return opResult{
Kind: OpCopy,
Status: StatusError,
Status: config.OpStatus.Error,
Source: src,
Target: dest,
Reason: err.Error(),
......@@ -90,7 +83,7 @@ func copyIfMissing(src, dest string, opts opOptions) opResult {
return opResult{
Kind: OpCopy,
Status: StatusDone,
Status: config.OpStatus.Done,
Source: src,
Target: dest,
}
......@@ -133,7 +126,7 @@ func createLinkIfMissing(src, dest string, opts opOptions) opResult {
if _, err := os.Stat(src); os.IsNotExist(err) {
return opResult{
Kind: OpLink,
Status: StatusSkipped,
Status: config.OpStatus.Skipped,
Target: dest,
Reason: "source missing",
}
......@@ -142,7 +135,7 @@ func createLinkIfMissing(src, dest string, opts opOptions) opResult {
if _, err := os.Lstat(dest); err == nil {
return opResult{
Kind: OpLink,
Status: StatusSkipped,
Status: config.OpStatus.Skipped,
Target: dest,
Reason: "already exists",
}
......@@ -151,7 +144,7 @@ func createLinkIfMissing(src, dest string, opts opOptions) opResult {
if opts.DryRun {
return opResult{
Kind: OpLink,
Status: StatusDryRun,
Status: config.OpStatus.DryRun,
Source: src,
Target: dest,
}
......@@ -160,7 +153,7 @@ func createLinkIfMissing(src, dest string, opts opOptions) opResult {
if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil {
return opResult{
Kind: OpLink,
Status: StatusError,
Status: config.OpStatus.Error,
Reason: err.Error(),
}
}
......@@ -168,14 +161,14 @@ func createLinkIfMissing(src, dest string, opts opOptions) opResult {
if err := os.Symlink(src, dest); err != nil {
return opResult{
Kind: OpLink,
Status: StatusError,
Status: config.OpStatus.Error,
Reason: err.Error(),
}
}
return opResult{
Kind: OpLink,
Status: StatusDone,
Status: config.OpStatus.Done,
Source: src,
Target: dest,
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment