-
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.
feat(config): added new feature: set owner and group ID for result files
New options: UID, GID and IsRoot. They are the id of user/group in UNIX system. If you'll set UID(without IsRoot option), then the moved files will have a owner, that you specified in configuration. Option 'IsRoot', enables option to set ownership for root user(requiers root permission)
- Loading branch information
Showing
7 changed files
with
95 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package file | ||
|
||
import ( | ||
"github.com/wittano/filebot/setting" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
type uID int | ||
type gID int | ||
|
||
const ( | ||
rootID uID = 0 | ||
rootGID gID = 0 | ||
) | ||
|
||
func uid(path string, ogStat os.FileInfo, config setting.Config) uID { | ||
baseDir := filepath.Dir(path) | ||
|
||
for _, dir := range config.Dirs { | ||
if dir.Dest == baseDir { | ||
uid := uID(os.Getuid()) | ||
|
||
if dir.UID > 0 { | ||
uid = uID(dir.UID) | ||
} else if dir.IsRoot { | ||
uid = rootID | ||
} | ||
|
||
return uid | ||
} | ||
} | ||
|
||
return uID(ogStat.Sys().(*syscall.Stat_t).Uid) | ||
} | ||
|
||
func gid(path string, ogStat os.FileInfo, config setting.Config) gID { | ||
baseDir := filepath.Dir(path) | ||
|
||
for _, dir := range config.Dirs { | ||
if dir.Dest == baseDir { | ||
uid := gID(os.Getgid()) | ||
if dir.UID > 0 { | ||
uid = gID(dir.GID) | ||
} else if dir.IsRoot { | ||
uid = rootGID | ||
} | ||
|
||
return uid | ||
} | ||
} | ||
|
||
return gID(ogStat.Sys().(*syscall.Stat_t).Gid) | ||
} |
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
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