[1/2] configurehood: Copy local hoodfile to common location

Submitted by Fabian Blaese on Dec. 3, 2018, 7:54 p.m.

Details

Message ID 20181203195455.7261-1-fabian@blaese.de
State Accepted
Headers show

Commit Message

Fabian Blaese Dec. 3, 2018, 7:54 p.m.
Instead of overwriting local variable to local hoodfile location,
copy it to the commonly used location. This makes the local hoodfile
behave exactly like central hoodfiles, which prevents some border cases.

The previous behaviour mainly caused issues when using getJsonPath() and
getUpgradePath() from fff-hoodutils.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
---
 src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index de60c21..4ae1364 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -77,7 +77,7 @@  if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then
 fi
 
 if [ -s "$hoodfilelocal" ]; then
-	hoodfiletmp="$hoodfilelocal"
+	cp "$hoodfilelocal" "$hoodfiletmp"
 	echo "Use local hood file"
 else
 	# if we have Internet, we download the Hoodfile from the keyxchangev2

Comments

Adrian Schmutzler Dec. 6, 2018, 12:01 p.m.
Hallo Fabian,

auch wenn ich zunächst anderer Meinung war: Es ist so stimmiger. Das lokale Hoodfile wird einfach eine "Quelle" wie auch Gateway oder configap. Und alle 5 Minuten im (RAM-)Speicher schreiben tun wir bei den anderen Varianten ja auch.

Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

Ein paar Anmerkungen/Fragen:
- Macht cp auto-overwrite?
- Ich überlege, was passiert, wenn so ein File gerade geschrieben (per wget) oder kopiert wird. Liegt dann da für 2 sec. ein halbes File rum oder macht das das Dateisystem intelligenter? (Man könnte ja auch hoodfile.tmp schreiben und dann mv machen) Für configurehood wäre es wurscht, aber ggf. würde dann ein anderes Skript dieses halbe File auswerten und versterben. (Mir fällt allerdings nichts "wichtiges" außerhalb configurehood ein, wo es schlimm wäre, wenn das ganz selten kaputt geht).

Da wir hier an configurehood rumfummeln, würde ich den Patch etwas länger liegen lassen vor dem applien (ne Woche statt 2 Tage), falls noch jemand was zu sagen hat.

Beste Grüße

Adrian



> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of
> Fabian Bläse
> Sent: Montag, 3. Dezember 2018 20:55
> To: franken-dev@freifunk.net
> Subject: [PATCH 1/2] configurehood: Copy local hoodfile to common location
> 
> Instead of overwriting local variable to local hoodfile location,
> copy it to the commonly used location. This makes the local hoodfile
> behave exactly like central hoodfiles, which prevents some border cases.
> 
> The previous behaviour mainly caused issues when using getJsonPath() and
> getUpgradePath() from fff-hoodutils.
> 
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index de60c21..4ae1364 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -77,7 +77,7 @@ if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then
>  fi
> 
>  if [ -s "$hoodfilelocal" ]; then
> -	hoodfiletmp="$hoodfilelocal"
> +	cp "$hoodfilelocal" "$hoodfiletmp"
>  	echo "Use local hood file"
>  else
>  	# if we have Internet, we download the Hoodfile from the
> keyxchangev2
> --
> 2.19.1
Fabian Blaese Dec. 7, 2018, 3:18 p.m.
Hallo Adrian,

On 06.12.18 13:01, Adrian Schmutzler wrote:
> Ein paar Anmerkungen/Fragen:
> - Macht cp auto-overwrite?
Mit default settings: ja.

> - Ich überlege, was passiert, wenn so ein File gerade geschrieben (per wget) oder kopiert wird. Liegt dann da für 2 sec. ein halbes File rum oder macht das das Dateisystem intelligenter? (Man könnte ja auch hoodfile.tmp schreiben und dann mv machen) Für configurehood wäre es wurscht, aber ggf. würde dann ein anderes Skript dieses halbe File auswerten und versterben. (Mir fällt allerdings nichts "wichtiges" außerhalb configurehood ein, wo es schlimm wäre, wenn das ganz selten kaputt geht).
Das Dateisystem spielt hierbei keine Rolle. Die Frage ist, wie man mit dem OS kommuniziert.
Wenn man eine Datei zum überschreiben truncated (Auf Länge 0 gekürzt) und dann rein schreibt, dann liegt für den Zeitraum des Downloads eine "kaputte" Datei rum.
Verschiebt man eine Datei, dann bleibt der Dateiinhalt ja der gleiche und man verändert nur inodes. Dann passiert das ganze so atomar, dass man entweder eine vollständige Datei ließt, oder gar keine.

mv ist daher (natürlich nur innerhalb eines Dateisystems) atomar. wget und cp truncaten beim Überschreiben und laden dann direkt in die Datei, jedenfalls mit Standardoptionen.
Es gibt im Linux File Locks, da kenne ich mich aber nicht so genau aus.
Man könnte natürlich immer noch zusätzlich woanders hin laden und dann verschieben. Aber diese Operationen gehen so schnell (hoodfilewww wird iirc nur von cp geschreiben), dass eine Überschneidung so absurd unwahrscheinlich ist, dass ich nicht glaube dass hier ein Problem ist. Aber hübscher wäre es natürlich.

Gruß
Fabian
Robert Langhammer Dec. 8, 2018, 7:30 p.m.
Hi Fabian,

Reviewed-by: Robert Langhammer <rlanghammer@web.de>


Oh mann, dieses configurehood! Das ist zwar nur eine Zeile, aber bis man
wieder drin ist und versteht, wo das ueberall greifen koennte, puh!

Am 03.12.18 um 20:54 schrieb Fabian Bläse:
> Instead of overwriting local variable to local hoodfile location,
> copy it to the commonly used location. This makes the local hoodfile
> behave exactly like central hoodfiles, which prevents some border cases.
>
> The previous behaviour mainly caused issues when using getJsonPath() and
> getUpgradePath() from fff-hoodutils.
>
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index de60c21..4ae1364 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -77,7 +77,7 @@ if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then
>  fi
>  
>  if [ -s "$hoodfilelocal" ]; then
> -	hoodfiletmp="$hoodfilelocal"
> +	cp "$hoodfilelocal" "$hoodfiletmp"
>  	echo "Use local hood file"
>  else
>  	# if we have Internet, we download the Hoodfile from the keyxchangev2
Adrian Schmutzler Dec. 9, 2018, 1:35 p.m.
Beide Applied.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of robert
> Sent: Samstag, 8. Dezember 2018 20:30
> To: franken-dev@freifunk.net
> Subject: Re: [PATCH 1/2] configurehood: Copy local hoodfile to common
> location
> 
> Hi Fabian,
> 
> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
> 
> 
> Oh mann, dieses configurehood! Das ist zwar nur eine Zeile, aber bis man
> wieder drin ist und versteht, wo das ueberall greifen koennte, puh!
> 
> Am 03.12.18 um 20:54 schrieb Fabian Bläse:
> > Instead of overwriting local variable to local hoodfile location, copy
> > it to the commonly used location. This makes the local hoodfile behave
> > exactly like central hoodfiles, which prevents some border cases.
> >
> > The previous behaviour mainly caused issues when using getJsonPath()
> > and
> > getUpgradePath() from fff-hoodutils.
> >
> > Signed-off-by: Fabian Bläse <fabian@blaese.de>
> > ---
> >  src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > index de60c21..4ae1364 100755
> > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > @@ -77,7 +77,7 @@ if [ -s "$hoodfilewww" ] && isGatewayAvailable ;
> > then  fi
> >
> >  if [ -s "$hoodfilelocal" ]; then
> > -	hoodfiletmp="$hoodfilelocal"
> > +	cp "$hoodfilelocal" "$hoodfiletmp"
> >  	echo "Use local hood file"
> >  else
> >  	# if we have Internet, we download the Hoodfile from the
> > keyxchangev2