@@ -3,9 +3,9 @@ package engine
33import (
44 "errors"
55 "os"
6- "path/filepath"
76 "strings"
87 "syscall"
8+ "time"
99
1010 services "github.com/gen0cide/service-go"
1111 "github.com/mitchellh/go-ps"
@@ -103,7 +103,7 @@ func (e *Engine) FindProcByName(procName string) (int, error) {
103103//
104104func (e * Engine ) InstallSystemService (path , name , displayName , description string ) error {
105105 c := & services.Config {
106- Path : filepath . Clean ( path ) ,
106+ Path : path ,
107107 Name : name ,
108108 DisplayName : displayName ,
109109 Description : description ,
@@ -470,3 +470,161 @@ func (e *Engine) EnvVars() map[string]string {
470470func (e * Engine ) GetEnvVar (eVar string ) string {
471471 return os .Getenv (eVar )
472472}
473+
474+ // SelfPath - Retrieves the path to the currently running executable.
475+ //
476+ // Package
477+ //
478+ // os
479+ //
480+ // Author
481+ //
482+ // - gen0cide (https://github.com/gen0cide)
483+ //
484+ // Javascript
485+ //
486+ // Here is the Javascript method signature:
487+ // SelfPath()
488+ //
489+ // Arguments
490+ //
491+ // Here is a list of the arguments for the Javascript function:
492+ //
493+ // Returns
494+ //
495+ // Here is a list of fields in the return object:
496+ // * obj.path (string)
497+ // * obj.osError (error)
498+ //
499+ // Example
500+ //
501+ // Here is an example of how to use this function in gscript:
502+ // var obj = SelfPath();
503+ // // obj.path
504+ // // obj.osError
505+ //
506+ func (e * Engine ) SelfPath () (string , error ) {
507+ return os .Executable ()
508+ }
509+
510+ // Chmod - Change the permissions on a path.
511+ //
512+ // Package
513+ //
514+ // os
515+ //
516+ // Author
517+ //
518+ // - gen0cide (https://github.com/gen0cide)
519+ //
520+ // Javascript
521+ //
522+ // Here is the Javascript method signature:
523+ // Chmod(path, perms)
524+ //
525+ // Arguments
526+ //
527+ // Here is a list of the arguments for the Javascript function:
528+ // * path (string)
529+ // * perms (int64)
530+ //
531+ // Returns
532+ //
533+ // Here is a list of fields in the return object:
534+ // * obj.osError (error)
535+ //
536+ // Example
537+ //
538+ // Here is an example of how to use this function in gscript:
539+ // var obj = Chmod(path, perms);
540+ // // obj.osError
541+ //
542+ func (e * Engine ) Chmod (path string , perms int64 ) error {
543+ if err := os .Chmod (path , os .FileMode (uint32 (perms ))); err != nil {
544+ return err
545+ }
546+ return nil
547+ }
548+
549+ // ModTime - Retrieves the last modified time of a path.
550+ //
551+ // Package
552+ //
553+ // os
554+ //
555+ // Author
556+ //
557+ // - gen0cide (https://github.com/gen0cide)
558+ //
559+ // Javascript
560+ //
561+ // Here is the Javascript method signature:
562+ // ModTime(path)
563+ //
564+ // Arguments
565+ //
566+ // Here is a list of the arguments for the Javascript function:
567+ // * path (string)
568+ //
569+ // Returns
570+ //
571+ // Here is a list of fields in the return object:
572+ // * obj.modTime (int64)
573+ // * obj.fileError (error)
574+ //
575+ // Example
576+ //
577+ // Here is an example of how to use this function in gscript:
578+ // var obj = ModTime(path);
579+ // // obj.modTime
580+ // // obj.fileError
581+ //
582+ func (e * Engine ) ModTime (path string ) (int64 , error ) {
583+ f , err := os .Stat (path )
584+ if err != nil {
585+ return 0 , err
586+ }
587+ return f .ModTime ().Unix (), nil
588+ }
589+
590+ // ModifyTimestamp - Change the access and modified time of a file.
591+ //
592+ // Package
593+ //
594+ // os
595+ //
596+ // Author
597+ //
598+ // - gen0cide (https://github.com/gen0cide)
599+ //
600+ // Javascript
601+ //
602+ // Here is the Javascript method signature:
603+ // ModifyTimestamp(path, accessTime, modifyTime)
604+ //
605+ // Arguments
606+ //
607+ // Here is a list of the arguments for the Javascript function:
608+ // * path (string)
609+ // * accessTime (int64)
610+ // * modifyTime (int64)
611+ //
612+ // Returns
613+ //
614+ // Here is a list of fields in the return object:
615+ // * obj.fileError (error)
616+ //
617+ // Example
618+ //
619+ // Here is an example of how to use this function in gscript:
620+ // var obj = ModifyTimestamp(path, accessTime, modifyTime);
621+ // // obj.fileError
622+ //
623+ func (e * Engine ) ModifyTimestamp (path string , accessTime , modifyTime int64 ) error {
624+ aTime := time .Unix (accessTime , 0 )
625+ mTime := time .Unix (modifyTime , 0 )
626+ if err := os .Chtimes (path , aTime , mTime ); err != nil {
627+ return err
628+ }
629+ return nil
630+ }
0 commit comments