1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| type path_name struct { u_path string u_name string } func (u *cuser) touch(db *sql.DB, command string) { var valid bool = true var execString string var subpaths []path_name var queryRow *sql.Row var isdir, recordCount int var err error args := generateArgs(command, 4) if args == nil { fmt.Println("args format wrong") valid = false goto TOUCH_VERIFY } isdir, err = strconv.Atoi(args[3]) if err != nil || strings.ToUpper(args[0]) != "TOUCH" || !isFilenameValid(args[1]) || !isPathFormatValid(args[2]) || isdir != 0 && isdir != 1 { if err != nil { fmt.Println(err.Error()) } valid = false goto TOUCH_VERIFY } subpaths = generateSubpaths(args[2]) for _, subpath := range subpaths { queryRow = db.QueryRow(fmt.Sprintf(`select count(*) from ufile where ownerid=%d and filename='%s' and path='%s' and isdir=1`, u.id, subpath.u_name, subpath.u_path)) if queryRow == nil { valid = false goto TOUCH_VERIFY } err = queryRow.Scan(&recordCount) if err != nil { fmt.Println(err.Error()) valid = false goto TOUCH_VERIFY } if recordCount <= 0 { _, err = db.Exec(fmt.Sprintf(`insert into ufile values(null, %d, -1, '%s', '', '%s', 0, 0, '%s', 1, '', 1)`, u.id, subpath.u_path, time.Now().Format("2006-01-02 15:04:05"), subpath.u_name)) if err != nil { fmt.Println(err.Error()) valid = false } } }
execString = fmt.Sprintf(`insert into ufile values(null, %d, -1, '%s', '', '%s', 0, 0, '%s', 1, '', %d)`, u.id, args[2], time.Now().Format("2006-01-02 15:04:05"), args[1], isdir) fmt.Println(execString) _, err = db.Exec(execString) if err != nil { fmt.Println(err.Error()) valid = false } TOUCH_VERIFY: if !valid { u.listen.SendBytes(auth.Int64ToBytes(int64(400))) } else { u.listen.SendBytes(auth.Int64ToBytes(int64(200))) } }
|