How to select a file directory as a temporary storage in the snap design

Source: Internet
Author: User
Tags mkdir tmp file touch

In our application design, we will choose some temporary file directories to store our files, such as the TMP file directory in Linux. So in our snap design, which file directory should we use to store our files? The answer is that we can choose Xdg_runtime_dir, and of course it depends on the developer's own choice.


Let's first look at one of my good routines:

Https://github.com/liu-xiao-guo/helloworld-fifo

Its Snapcraft.yaml file is as follows:


Name:hello
Version: "1.0"
summary:the ' hello-world ' of snaps
description: |
    This was a simple snap example, includes a few interesting binaries to
    demonstrate snaps and their confinement.
  
   * hello-world.env  -Dump the env of commands run inside app Sandbox
    * hello-world.evil-show how snappy Sandboxe S binaries
    * hello-world.sh   -Enter interactive shell, runs in app Sandbox
    * hello-world      -Simply OU Tput text
grade:stable
confinement:strict
type:app  #it can be gadget or framework
Icon:icon . png

Apps:
 FIFO:
   command:bin/fifo
 env:
   command:bin/env
 Evil:
   command:bin/ Evil
 sh:
   command:bin/sh
 hello-world:
   command:bin/echo
 CreateFile:
   command:bin/ CreateFile
 createfiletohome:
   command:bin/createfiletohome
 Writetocommon:
   command:bin/ Writetocommon

parts:
 Hello:
  plugin:dump
  Source:.
  

Here, we have designed an application called FIFO. Its script is specific to the following:

#!/bin/bash

echo "Going to make a directory at: $XDG _runtime_dir"
mkdir-p $XDG _runtime_dir

echo "Create a fil E at the location ... "
CD $XDG _runtime_dir
pwd
Touch thisfile

if [$ = = 0]; then
	echo" The file is Su ccessfully created! "
else
	echo "The file is not successfully created!"
Fi

I first create a directory and create a file in the directory. Shown below:

liuxg@liuxg:~$ Hello.fifo 
going to make a directory in:/run/user/1000/snap.hello
Create A file at the location. ..
/run/user/1000/snap.hello The
file is successfully created!

Obviously this application is running without any permission problems. It is a location that can be fully accessed and read and written. This location can be used by our application for FIFO operation.

We can actually also run my env application in the app to show all the environment variables:

liuxg@liuxg:~$ hello.env | grep xdg_runtime_dir
Xdg_runtime_dir=/run/user/1000/snap.hello


Of course, we can also use the/tmp directory as a temporary storage file directory. This directory is unique for each snap application, which means that each application has its own standalone TMP directory. But we can all follow the/TMP way to visit. The location of this file can be found in the/tmp directory of our desktop computer. Its file directory is a bit like/tmp/snap.1000_snap.hello.fifo_5bpmib/tmp.

We can use the following code to test this: FIFO

#!/bin/bash

echo "Going to make a directory at: $XDG _runtime_dir"
mkdir-p $XDG _runtime_dir

echo "Create a fil E at the location ... "
CD $XDG _runtime_dir
pwd
Touch thisfile

if [$ = = 0]; then
	echo" The file is Su ccessfully created! "
else
	echo "The file is not successfully created!"
Fi

cd/tmp
pwd
echo "Haha" > Test.txt

if [$ = = 0]; then
	echo "The Test.txt file is SUCCESSF Ully created! "
else
	echo "The Test.txt file is not successfully created!"
Fi


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.