Beispiel #1
0
func DeleteFile(file File) {
	_, err := dbmap.Delete(&file)
	lib.CheckErr(err, "Delete file failed")
	filePath := strings.Join([]string{BuildsPath, file.Name}, "/")
	if _, err := os.Stat(filePath); err == nil {
		deletedPath := strings.Join([]string{BuildsPath, "deleted", file.Name}, "/")
		err = os.Rename(filePath, deletedPath)
		lib.CheckErr(err, "Move file to deleted directory failed")
	}
}
Beispiel #2
0
func PublishFile(file File) {
	filePath := strings.Join([]string{BuildsPath, file.Name}, "/")
	publishPath := strings.Join([]string{BuildsPath, "published", file.Name}, "/")
	if _, err := os.Stat(filePath); err == nil {
		// mv to /builds/production
		err := os.Rename(filePath, publishPath)
		lib.CheckErr(err, "Move file to published directory failed")
		// make read-only
		err = os.Chmod(publishPath, 0444)
		lib.CheckErr(err, "Chmod file to read-only failed")
	}
}
Beispiel #3
0
func UnpublishFile(file File) {
	filePath := strings.Join([]string{BuildsPath, file.Name}, "/")
	publishPath := strings.Join([]string{BuildsPath, "published", file.Name}, "/")
	if _, err := os.Stat(publishPath); err == nil {
		// make writeable
		err := os.Chmod(publishPath, 0777)
		lib.CheckErr(err, "Chmod file to writeable failed")
		// mv to /builds/production
		err = os.Rename(publishPath, filePath)
		lib.CheckErr(err, "Move file to builds directory failed")
	}
}
// GET /changelog/{incremental}.txt
func ChangelogFiles(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	file, err := models.FindFileByIncremental(vars["incremental"])
	lib.CheckErr(err, "Find by incremental failed")
	release := models.FindReleaseByFile(file)
	changelog := strings.Join([]string{"Release notes for Copperhead OS #", file.Incremental, "\n---\n", release.Changelog}, "")
	fmt.Fprintf(w, changelog)
}
func InitDb(dbPath string, builds string) *gorp.DbMap {
	log.Println("Connecting to database ", dbPath)
	db, err := sql.Open("sqlite3", dbPath)
	lib.CheckErr(err, "sql.Open failed")

	dbmap = &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
	dbmap.AddTableWithName(Release{}, "releases").SetKeys(true, "Id")
	dbmap.AddTableWithName(User{}, "users").SetKeys(true, "Id")
	dbmap.AddTableWithName(File{}, "files").SetKeys(true, "Id")

	//dbmap.DropTables()
	//err = dbmap.TruncateTables()

	err = dbmap.CreateTablesIfNotExists()
	lib.CheckErr(err, "Create tables failed")

	BuildsPath = builds
	return dbmap
}
Beispiel #6
0
func UpdateFile(file File) {
	_, err := dbmap.Update(&file)
	lib.CheckErr(err, "Update file failed")
}
Beispiel #7
0
func CreateFile(file File) {
	err := dbmap.Insert(&file)
	lib.CheckErr(err, "Insert file failed")
}
Beispiel #8
0
func FindFile(id int64) File {
	var file File
	err := dbmap.SelectOne(&file, "select * from files where file_id=?", id)
	lib.CheckErr(err, "Find file failed")
	return file
}
Beispiel #9
0
func FilesIndex() []File {
	var files []File
	_, err := dbmap.Select(&files, "select * from files order by file_id DESC")
	lib.CheckErr(err, "Select all files failed")
	return files
}
Beispiel #10
0
func Files() []File {
	var files []File
	_, err := dbmap.Select(&files, "select * from files where published=0")
	lib.CheckErr(err, "Select all files failed")
	return files
}
func ReleasesIndex() []Release {
	var releases []Release
	_, err := dbmap.Select(&releases, "select * from releases order by release_id DESC")
	lib.CheckErr(err, "Select all releases failed")
	return releases
}
func FindReleaseByFile(file File) Release {
	var release Release
	err := dbmap.SelectOne(&release, "select * from releases where FileId=? LIMIT 1", file.Id)
	lib.CheckErr(err, "Find release by file failed")
	return release
}
func FindRelease(id int64) Release {
	var release Release
	err := dbmap.SelectOne(&release, "select * from releases where release_id=? LIMIT 1", id)
	lib.CheckErr(err, "Find release failed")
	return release
}
func DeleteRelease(release Release) {
	_, err := dbmap.Delete(&release)
	lib.CheckErr(err, "Delete failed")
}
func UpdateRelease(release Release) {
	_, err := dbmap.Update(&release)
	lib.CheckErr(err, "Update failed")
}
func CreateRelease(release Release) {
	err := dbmap.Insert(&release)
	lib.CheckErr(err, "Insert release failed")
}