Пример #1
0
// path = "mydirectory"
// permissions = "rwxrw_r__"  // or permissions = "764"
//
// err = mkdir path [permissions]
//
func mkdir(th InterpreterThread, objects []RObject) []RObject {

	path := string(objects[0].(String))

	permStr := "766"
	if len(objects) > 1 {
		permStr = string(objects[1].(String))
	}

	perm, errStr := getFilePermissions(permStr)
	var err error
	if errStr == "" {
		err = gos.Mkdir(path, perm)
	}
	if err != nil {
		errStr = err.Error()
	}
	return []RObject{String(errStr)}
}
func copyDocDirTree(fromDocDirPath string, toDocDirPath string) (err error) {

	var dir *os.File
	var filesInDir []os.FileInfo
	dir, err = gos.Open(fromDocDirPath)
	filesInDir, err = dir.Readdir(0)
	if err != nil {
		return
	}
	err = dir.Close()

	err = gos.Mkdir(toDocDirPath, 0777)

	for _, fileInfo := range filesInDir {
		fromItemPath := fromDocDirPath + "/" + fileInfo.Name()
		toItemPath := toDocDirPath + "/" + fileInfo.Name()
		if fileInfo.IsDir() {
			err = copyDocDirTree(fromItemPath, toItemPath)
			if err != nil {
				return
			}
		} else { // plain old file to be copied.
			if strings.HasSuffix(fileInfo.Name(), ".txt") || strings.HasSuffix(fileInfo.Name(), ".html") || strings.HasSuffix(fileInfo.Name(), ".htm") || strings.HasSuffix(fileInfo.Name(), ".css") {
				var content []byte
				content, err = gos.ReadFile(fromItemPath)
				if err != nil {
					return
				}
				err = gos.WriteFile(toItemPath, content, 0666)
				if err != nil {
					return
				}
			}
		}
	}
	return
}