Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check config file keys for validity, use setValue instead of direct access #296

Merged
merged 4 commits into from
Dec 19, 2018

Conversation

norbusan
Copy link
Collaborator

All possible values are already initialized in init before the config file is loaded. Check the keys of the config files against the existing keys and warn in case of mismatch.

Furthermore, instead of directly changing the values array, use the setValue function to allow for easier reimplementation of the configuration storage.

@norbusan
Copy link
Collaborator Author

My recommendation is to include this into 2.2.2 milestone, to fix things like what has happened in #293

@abraunegg abraunegg added this to the 2.2.2 milestone Dec 19, 2018
@abraunegg
Copy link
Owner

For some reason this change ignore's this in the config file:

# Drive ID for SharePoint Shared Library
drive_id = "b!6H_y8BWP8Uqg2X0QAy4XfxiTMFe_reZKrMZXLeBjL4g70-n16rIGQpOG_l7vVxU5"

Output with this PR:

./onedrive --confdir '~/odconfig/' --synchronize --verbose 
Loading config ...
Using Config Dir: /home/alex/odconfig/
Unknown key in config file: drive_id
Initializing the OneDrive API ...
Opening the item database ...
All operations will be performed in: /home/alex/OneDriveALT
Initializing the Synchronization Engine ...
Account Type: business
Default Drive ID: b!xA9hqR7mT0OL6Gku8YbuzTJ8oZmRnQZJu6-yDL49Zc5MccrHbuT0R4QUwIzUvbJY
Default Root ID: 01D6JQORV6Y2GOVW7725BZO354PWSELRRZ
Remaining Free Space: 1099511108257
Fetching details for OneDrive Root
OneDrive Root exists in the database
Syncing changes from OneDrive ...
Applying changes of Path ID: 01D6JQORV6Y2GOVW7725BZO354PWSELRRZ
Uploading differences of .
Processing root
The directory has not changed
Processing 4
The directory has not changed
Processing Document.docx
The file has not changed
Processing 2
The directory has not changed
Processing Document.docx
The file has not changed
Processing 1
The directory has not changed
Processing 1.txt
The file has not changed
Processing 3
The directory has not changed
Processing Presentation.pptx
The file has not changed
Uploading new items of .
Applying changes of Path ID: 01D6JQORV6Y2GOVW7725BZO354PWSELRRZ

Output with master:

./onedrive --confdir '~/odconfig/' --synchronize --verbose 
Loading config ...
Using Config Dir: /home/alex/odconfig/
Initializing the OneDrive API ...
Opening the item database ...
All operations will be performed in: /home/alex/OneDriveALT
Initializing the Synchronization Engine ...
Account Type: documentLibrary
Default Drive ID: b!6H_y8BWP8Uqg2X0QAy4XfxiTMFe_reZKrMZXLeBjL4g70-n16rIGQpOG_l7vVxU5
Default Root ID: 01LWWIJZN6Y2GOVW7725BZO354PWSELRRZ
Remaining Free Space: 27487788820266
Fetching details for OneDrive Root
OneDrive Root exists in the database
Syncing changes from OneDrive ...
Applying changes of Path ID: 01LWWIJZN6Y2GOVW7725BZO354PWSELRRZ
Uploading differences of .
Processing root
The directory has not changed
Processing 4
The directory has not changed
Processing Document.docx
The file has not changed
Processing 2
The directory has not changed
Processing Document.docx
The file has not changed
Processing 1
The directory has not changed
Processing 1.txt
The file has not changed
Processing 3
The directory has not changed
Processing Presentation.pptx
The file has not changed
Uploading new items of .
Applying changes of Path ID: 01LWWIJZN6Y2GOVW7725BZO354PWSELRRZ

Note the switch to the Office 365 Shared Library because 'drive_id' was in the config

Also, if ddrive_id is used, this is not picked up by itself, however if there is a spelling error in any of the other config options then ddrive_id is picked up:

./onedrive --confdir '~/odconfig/' --synchronize --verbose 
Loading config ...
Using Config Dir: /home/alex/odconfig/
Unknown key in config file: ssync_dir
Unknown key in config file: skkip_file
Unknown key in config file: moniitor_interval
Unknown key in config file: ddrive_id
Initializing the OneDrive API ...
Opening the item database ...
All operations will be performed in: /home/alex/OneDrive
Initializing the Synchronization Engine ...
Account Type: business
Default Drive ID: b!xA9hqR7mT0OL6Gku8YbuzTJ8oZmRnQZJu6-yDL49Zc5MccrHbuT0R4QUwIzUvbJY
Default Root ID: 01D6JQORV6Y2GOVW7725BZO354PWSELRRZ
Remaining Free Space: 1099511108257
Fetching details for OneDrive Root
OneDrive Root exists in the database

If drive_id is spelt OK, but a prior key is not, then this is picked up as being invalid:

./onedrive --confdir '~/odconfig/' --synchronize --verbose 
Loading config ...
Using Config Dir: /home/alex/odconfig/
Unknown key in config file: moniitor_interval
Unknown key in config file: drive_id
Initializing the OneDrive API ...
Opening the item database ...
All operations will be performed in: /home/alex/OneDriveALT
Initializing the Synchronization Engine ...
Account Type: business
Default Drive ID: b!xA9hqR7mT0OL6Gku8YbuzTJ8oZmRnQZJu6-yDL49Zc5MccrHbuT0R4QUwIzUvbJY
Default Root ID: 01D6JQORV6Y2GOVW7725BZO354PWSELRRZ
...

@norbusan
Copy link
Collaborator Author

Ahh. indeed ... because drive_id is not initially set ... I thought that config.d:init does set all possible config options:

        void init()
        {
                // Default configuration directory
                setValue("sync_dir", "~/OneDrive");
                // Configure to skip ONLY temp files (~*.doc etc) by default
                // Prior configuration was: .*|~*
                setValue("skip_file", "~*");
                // By default symlinks are not skipped (using string type
                // instead of boolean because hashmap only stores string types)
                setValue("skip_symlinks", "false");
                // Configure the monitor mode loop - the number of seconds by which
                // each sync operation is undertaken when idle under monitor mode
                setValue("monitor_interval", "45");
                // Configure the default logging directory to be /var/log/onedrive/
                setValue("log_dir", "/var/log/onedrive/");
                
                if (!load(userConfigFilePath)) {
                        log.vlog("No config file found, using defaults");
                }
        }

but that was wrong.

How can one find the definitive list of allowed config options?

@abraunegg
Copy link
Owner

abraunegg commented Dec 19, 2018

How can one find the definitive list of allowed config options?

drive_id is the only option that is 'not' set currently via config.d:init and is called via onedrive.d:init

Looking right now at this as if drive_id is set to an empty string via config.d:init what impact this has

@abraunegg
Copy link
Owner

abraunegg commented Dec 19, 2018

OK .. that has the desired effect where now 'drive_id' is correctly picked up.

I am thinking here as well - if there is a 'config' file issue, we don't allow the application to sync - as, if for example the 'drive_id' is spelt incorrectly, the actual account 'drive_id' would be used - which is what led to #293

Add 'drive_id' to be initialised, set to an empty string
* Issue #293 was caused by a spelling error in the configuration file. If the configuration file has errors, we should not load it or run using the application defaults as this may have undesirable consequences for users data
* Missed this edit of the file
@abraunegg
Copy link
Owner

I think this is good to merge now - thoughts?

@norbusan norbusan merged commit 025a3b2 into master Dec 19, 2018
@norbusan norbusan deleted the norbert/check-conf-values branch December 19, 2018 23:52
@norbusan
Copy link
Collaborator Author

Thanks, merged!

@adudek
Copy link

adudek commented Dec 20, 2018

For some reason --syncdir option is ignored when starting onedrive with latest master code. This caused all my items to be deleted when docker image was used --syncdir /onedrive/data.

Message on output showed that it will sync /home/onedrive/OneDrive folder.

@adudek adudek mentioned this pull request Dec 20, 2018
@lock
Copy link

lock bot commented Jan 5, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Jan 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants