Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Conversation

@procount
Copy link
Contributor

To fix #341 part 1.
Diff makes this look more complicated than it is.
Essentially the copy of wpa_supplicant.conf has been taken out of startNetwokring() into copywpa() which is then called ahead of startNetworking() regardless of silentinstall option.
Then copywpa() was modified to provide the necessary functionality.

(This PR is a copy/paste out of PINN into NOOBS)

_fixate = true;
}

copywpa();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a capital W ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Don't know where it went - it's there in my original code. Odd.

qDebug() << "Copying /etc/wpa_supplicant.conf to /settings/wpa_supplicant.conf";
QFile::copy("/etc/wpa_supplicant.conf", "/settings/wpa_supplicant.conf");
}
qDebug() << "Copying user wpa_supplicant.conf to /settings/wpa_supplicant.conf";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two spaces between "Copying" and "user" ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eagle-eyed! Yes.

QProcess::execute("mount -o remount,rw /settings");
QProcess::execute("mount -o remount,rw /mnt");

QFile::remove("/settings/wpa_supplicant.conf.bak");
Copy link
Collaborator

@lurch lurch Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it'd be worth making a little backup utility function which does something like (pseudocode):

bool backup(filename, ext="bak") {
    backupname = filename + "." + ext;
    if (exists(backupname)) {
        remove(backupname);
    }
    return rename(filename, backupname);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe...

QFile::copy("/mnt/wpa_supplicant.conf", "/settings/wpa_supplicant.conf");
f.setPermissions( QFile::WriteUser | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser );

/* rename the user file to avoid overwriting any manually set SSIDs */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this comment is a bit confusing - is it essentially the same as saying "rename the user file to indicate that it has been copied (and prevent it being re-copied next time)" ?

Although I guess this breaks the "NOOBS prime directive" of not modifying any files on the RECOVERY partition. Although I've not been keeping up to date with NOOBS for a while, so I dunno if that prime-directive is still in place? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I was concentrating more on the consequences of it being copied a second time.

Dunno either, but I wasn't too concerned about that in PINN. Not sure if there's another way around it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess with having the same configuration file stored / copied / edited in two different places, there'll never be a "perfect" way of doing things, so it's probably one of those "pick the least worst" situations ;)

@procount
Copy link
Contributor Author

procount commented Mar 2, 2018

Any better? I've compiled it on another branch, but not tested.

{

QString backupName = filename + "." + ext;
const char * backupFile = backupName.toUtf8().constData();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why the switch away from the Qt functions (QString, QFile::remove, QFile::rename, etc.) ? I think that might allow you to get rid of the ugly .toUtf8().constData() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I took your pseudo code too literally :) - I will revert.

recovery/util.h Outdated

QByteArray getFileContents(const QString &filename);
void putFileContents(const QString &filename, const QByteArray &data);
bool backup(QString filename, QString ext="bak");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be const QString &filename just like putFileContents uses? ;-)

QFile::remove(backupName);
}
return rename(filename.toUtf8().constData(), backupFile);
return QFile::rename(filename,backupName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo much neater 🎉

recovery/util.h Outdated
QByteArray getFileContents(const QString &filename);
void putFileContents(const QString &filename, const QByteArray &data);
bool backup(QString filename, QString ext="bak");
bool backup(const QString &filename, const QString &ext="bak");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the other functions declared here, perhaps backupFile would be a better name? :)
(sorry for being so nit-picky!)

procount added 3 commits March 4, 2018 18:03
Changed backup ->backupFile
Changed backup -> backupFile
Changed backup -> backupFile
@XECDesign XECDesign merged commit 0f7ad02 into raspberrypi:master Oct 4, 2018
@XECDesign
Copy link
Contributor

Thanks

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.

NOOBS wifi preconfig

3 participants