Created
August 19, 2013 11:52
-
-
Save christopherobin/6268335 to your computer and use it in GitHub Desktop.
Working an ALPM (ArchLinux Package Manager) library for Go
This file contains hidden or 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
package alpm | |
// #cgo LDFLAGS: -lalpm | |
// #include <alpm.h> | |
import "C" | |
//import "fmt" | |
import "errors" | |
type ALPM struct { | |
Root string | |
DBPath string | |
// private stuff | |
handle *C.alpm_handle_t | |
} | |
func CreateALPM(root, dbpath string) ALPM { | |
return ALPM{root, dbpath, nil} | |
} | |
func (alpm *ALPM) Initialize() error { | |
var result C.alpm_errno_t | |
alpm.handle = C.alpm_initialize(C.CString(alpm.Root), C.CString(alpm.DBPath), &result) | |
if (result != 0) { | |
return errors.New(C.GoString(C.alpm_strerror(result))) | |
} | |
return nil | |
} | |
func (alpm *ALPM) Release() error { | |
n, err := C.alpm_release(alpm.handle) | |
// reset handle | |
alpm.handle = nil; | |
if (n != 0) { | |
return errors.New("Couldn't release handle") | |
} | |
if (err != nil) { | |
return err | |
} | |
return nil | |
} | |
func (alpm *ALPM) GetLocalDb() DB { | |
db := C.alpm_get_localdb(alpm.handle) | |
return DB{db} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment