mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] environment: allow saving of symbolic link changes
       [not found] <cover.1450267988.git.zahari.doychev@linux.com>
@ 2015-12-16 12:24 ` Zahari Doychev
  2015-12-17  9:52   ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Zahari Doychev @ 2015-12-16 12:24 UTC (permalink / raw)
  To: barebox, s.hauer

Currently it is not possible to change symbolic links in the default
environment. For example if the default environment contains the
link "current_boot -> mmc" then the following does not work:

$ rm current_boot
$ ln net current_boot
$ saveenv

After reset the link is still pointing to "mmc" and this error appears:

"symlink: /env/boot/current_boot -> net : error -17"

The patch fixes the above problem and moves the "ENV_FLAG_NO_OVERWRITE"
to enable handling of symbolic links in this case too.

Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>
---
 common/environment.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index f412e62..9cf44a0 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -23,7 +23,6 @@
  * the default environment when building the barebox binary. So
  * do not add any new barebox related functions here!
  */
-
 #ifdef __BAREBOX__
 #include <common.h>
 #include <command.h>
@@ -417,6 +416,7 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
 	int headerlen_full;
 	/* for envfs < 1.0 */
 	struct envfs_inode_end inode_end_dummy;
+	struct stat s;
 
 	inode_end_dummy.mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
 	inode_end_dummy.magic = ENVFS_32(ENVFS_INODE_END_MAGIC);
@@ -460,11 +460,20 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
 		make_directory(dirname(tmp));
 		free(tmp);
 
+		ret = stat(str, &s);
+		if (!ret && (flags & ENV_FLAG_NO_OVERWRITE)) {
+			printf("skip %s\n", str);
+			goto skip;
+		}
+
 		if (S_ISLNK(ENVFS_32(inode_end->mode))) {
 			debug("symlink: %s -> %s\n", str, (char*)buf);
 			if (!strcmp(buf, basename(str))) {
 				unlink(str);
 			} else {
+				if (!ret)
+					unlink(str);
+
 				ret = symlink(buf, str);
 				if (ret < 0)
 					printf("symlink: %s -> %s : %s\n",
@@ -472,14 +481,6 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
 			}
 			free(str);
 		} else {
-			struct stat s;
-
-			if (flags & ENV_FLAG_NO_OVERWRITE &&
-					!stat(str, &s)) {
-				printf("skip %s\n", str);
-				goto skip;
-			}
-
 			fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
 			free(str);
 			if (fd < 0) {
-- 
2.6.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] environment: allow saving of symbolic link changes
  2015-12-16 12:24 ` [PATCH] environment: allow saving of symbolic link changes Zahari Doychev
@ 2015-12-17  9:52   ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-12-17  9:52 UTC (permalink / raw)
  To: Zahari Doychev; +Cc: barebox

Hi Zahari,

On Wed, Dec 16, 2015 at 01:24:43PM +0100, Zahari Doychev wrote:
> Currently it is not possible to change symbolic links in the default
> environment. For example if the default environment contains the
> link "current_boot -> mmc" then the following does not work:
> 
> $ rm current_boot
> $ ln net current_boot
> $ saveenv
> 
> After reset the link is still pointing to "mmc" and this error appears:
> 
> "symlink: /env/boot/current_boot -> net : error -17"
> 
> The patch fixes the above problem and moves the "ENV_FLAG_NO_OVERWRITE"
> to enable handling of symbolic links in this case too.
> 
> Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>

Applied, thanks.

BTW for this particular case I would rather recommend using nv
variables, i.e. nv boot.default=net or nv boot.default=mmc; saveenv.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-17  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1450267988.git.zahari.doychev@linux.com>
2015-12-16 12:24 ` [PATCH] environment: allow saving of symbolic link changes Zahari Doychev
2015-12-17  9:52   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox