wip-flag-migration #28

Merged
Alfred-mk merged 44 commits from wip-flag-migration into master 2024-09-04 11:25:34 +02:00
Owner
No description provided.
lash added 24 commits 2024-09-02 16:45:19 +02:00
Alfred-mk added 1 commit 2024-09-02 20:07:14 +02:00
carlos added 4 commits 2024-09-02 20:12:20 +02:00
lash reviewed 2024-09-03 00:32:23 +02:00
lash left a comment
Author
Owner

Silly, I made the pull request so the review can only be marked as comment...

Silly, I made the pull request so the review can only be marked as comment...
cmd/main.go Outdated
@ -54,0 +48,4 @@
}
// Register all flags loaded from pp.csv
flagKeys := []string{
Author
Owner

these flags should be loaded not hardcoded.

these flags should be loaded not hardcoded.
Alfred-mk marked this conversation as resolved
cmd/main.go Outdated
@ -54,0 +67,4 @@
"flag_incorrect_date_format",
}
for _, key := range flagKeys {
Author
Owner

iterate on csv lines and populate with rows 2 and 3...

iterate on csv lines and populate with rows 2 and 3...
Alfred-mk marked this conversation as resolved
@ -38,2 +66,3 @@
func NewHandlers(path string, st *state.State) *Handlers {
func NewHandlers(dir string, st *state.State) (*Handlers, error) {
db, err := gdbm.Open(dbFile, gdbm.ModeWrcreat)
Author
Owner

FYI this will truncate the file on every open.

... but lets not spend time on that, as it needs to be changed to the new gdbm implementation anyway.

FYI this will truncate the file on every open. ... but lets not spend time on that, as it needs to be changed to the new gdbm implementation anyway.
Member

So a question on this,we want to be able to keep a reference to the file created for each session and be able to initialize a database instance depending on its existence.So we have this code and it still seems to be removing the previously stored information when it is opened with mode ModeWriter .A fix for the time being for this will be appreciated because the refactoring depends on storing the user information to gdbm.

filename := path.Join(scriptDir, sessionId+"_userdata.gdbm")
_, err := os.Open(filename)
if err != nil {
	// Check if the error is due to the file not existing
	if os.IsNotExist(err) {
		fmt.Printf("File open error: the file '%s' does not exist\n", filename)
		db, err = gdbm.Open(filename, gdbm.ModeWrcreat)
		if err != nil {
			panic(err)
		}
	} else {
		panic(err)
	}
} else {
	db, err = gdbm.Open(filename, gdbm.ModeWriter)
	if err != nil {
		panic(err)
	}
}`                                                                                                                                                                                                                                                               
So a question on this,we want to be able to keep a reference to the file created for each session and be able to initialize a database instance depending on its existence.So we have this code and it still seems to be removing the previously stored information when it is opened with mode **ModeWriter** .A fix for the time being for this will be appreciated because the refactoring depends on storing the user information to gdbm. filename := path.Join(scriptDir, sessionId+"_userdata.gdbm") _, err := os.Open(filename) if err != nil { // Check if the error is due to the file not existing if os.IsNotExist(err) { fmt.Printf("File open error: the file '%s' does not exist\n", filename) db, err = gdbm.Open(filename, gdbm.ModeWrcreat) if err != nil { panic(err) } } else { panic(err) } } else { db, err = gdbm.Open(filename, gdbm.ModeWriter) if err != nil { panic(err) } }`
Author
Owner

First, as I said, let's not spend time on this, since this code will be gone when you implement db.gdbmDb in dev-0.1.0.

That said, choosing flag on os.Stat would be the way to go, I guess.

As a reference example on how to do it directly, see go-vise branch dev-0.1.0 method db/gdbm/gdbmDb.Connect(...)

But I repeat, please don't spend time on this.

First, as I said, let's not spend time on this, since this code will be gone when you implement db.gdbmDb in dev-0.1.0. That said, choosing flag on os.Stat would be the way to go, I guess. As a reference example on how to do it directly, see `go-vise` branch `dev-0.1.0` method `db/gdbm/gdbmDb.Connect(...)` But I repeat, please don't spend time on this.
@ -60,1 +98,4 @@
func (h *Handlers) PreloadFlags(flagKeys []string) (map[string]uint32, error) {
flags := make(map[string]uint32)
for _, key := range flagKeys {
Author
Owner

It shouldn't be necessary to process the flags twice.

It shouldn't be necessary to process the flags twice.
Alfred-mk marked this conversation as resolved
@ -85,2 +143,3 @@
err := h.accountFileHandler.EnsureFileExists()
// Preload the required flags
flagKeys := []string{"flag_account_created", "flag_account_creation_failed"}
Author
Owner

also seems unnecessary, there should be one single source of flag label to value map.

also seems unnecessary, there should be one single source of flag label to value map.
Member

For clarity, do you mean that we should load all flags once in the menuhandler and have functions access the already loaded flags?

For clarity, do you mean that we should load all flags once in the menuhandler and have functions access the already loaded flags?
Author
Owner

yes, or perhaps even globally.

yes, or perhaps even globally.
Alfred-mk marked this conversation as resolved
@ -88,3 +148,4 @@
return res, err
}
// err = h.accountFileHandler.EnsureFileExists()
Author
Owner

please remove commented code if it is not of any more use

please remove commented code if it is not of any more use
carlos marked this conversation as resolved
@ -156,3 +222,2 @@
case "2":
res.FlagReset = append(res.FlagSet, models.USERFLAG_ALLOW_UPDATE)
res.FlagSet = append(res.FlagSet, models.USERFLAG_SINGLE_EDIT)
res.FlagReset = append(res.FlagSet, flags["flag_allow_update"])
Author
Owner

here appends to set but assign to reset. happens in the below, too.

here appends to set but assign to reset. happens in the below, too.
Alfred-mk marked this conversation as resolved
@ -546,1 +629,3 @@
return res, err
err = h.db.Delete([]byte(Amount))
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
panic(err)
Author
Owner

we cannot have panics anywhere in the vm execution! Just return error.

we cannot have panics anywhere in the vm execution! Just return error.
carlos marked this conversation as resolved
carlos added 2 commits 2024-09-03 10:51:42 +02:00
carlos added 1 commit 2024-09-03 12:19:53 +02:00
Alfred-mk added 1 commit 2024-09-03 14:03:01 +02:00
Alfred-mk added 1 commit 2024-09-03 14:04:25 +02:00
carlos added 2 commits 2024-09-03 14:09:46 +02:00
carlos added 1 commit 2024-09-03 14:14:15 +02:00
Alfred-mk added 1 commit 2024-09-03 14:34:39 +02:00
carlos added 2 commits 2024-09-03 17:00:33 +02:00
Alfred-mk added 1 commit 2024-09-03 18:06:58 +02:00
Alfred-mk added 1 commit 2024-09-03 21:29:12 +02:00
lash reviewed 2024-09-04 08:03:05 +02:00
@ -54,0 +71,4 @@
}
// Register the flag
state.FlagDebugger.Register(uint32(flagValue), flagName)
Author
Owner

A logline to show debug the flag loaded would be nice

A logline to show debug the flag loaded would be nice
@ -32,0 +56,4 @@
// FlagManager handles centralized flag management
type FlagManager struct {
parser *asm.FlagParser
mu sync.RWMutex
Author
Owner

I don't think mutex is needed here, it will be loaded once (before threads) and only read from then right?

I don't think mutex is needed here, it will be loaded once (before threads) and only read from then right?
Alfred-mk marked this conversation as resolved
Alfred-mk added 1 commit 2024-09-04 11:02:13 +02:00
Alfred-mk added 1 commit 2024-09-04 11:20:04 +02:00
Alfred-mk merged commit c6c66f956a into master 2024-09-04 11:25:34 +02:00
kamikazechaser reviewed 2024-09-04 13:07:48 +02:00
@ -87,0 +110,4 @@
ussdHandlers, err := ussd.NewHandlers(fp, &st, sessionId)
if err != nil {
fmt.Fprintf(os.Stderr, "handler setup failed with error: %v\n", err)

Exit in main if any setup fails.

Exit in main if any setup fails.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: urdt/ussd#28
No description provided.