示例#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")
	}
}
示例#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")
	}
}
示例#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)
}
示例#5
0
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
}
示例#6
0
func UpdateFile(file File) {
	_, err := dbmap.Update(&file)
	lib.CheckErr(err, "Update file failed")
}
示例#7
0
func CreateFile(file File) {
	err := dbmap.Insert(&file)
	lib.CheckErr(err, "Insert file failed")
}
示例#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
}
示例#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
}
示例#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
}
示例#11
0
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
}
示例#12
0
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
}
示例#13
0
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
}
示例#14
0
func DeleteRelease(release Release) {
	_, err := dbmap.Delete(&release)
	lib.CheckErr(err, "Delete failed")
}
示例#15
0
func UpdateRelease(release Release) {
	_, err := dbmap.Update(&release)
	lib.CheckErr(err, "Update failed")
}
示例#16
0
func CreateRelease(release Release) {
	err := dbmap.Insert(&release)
	lib.CheckErr(err, "Insert release failed")
}