如何在snap设计中选择文件目录作为临时存储
2017-02-04 11:37
686 查看
在我们的应用设计中,我们通过会选择一些临时的文件目录来存储我们的文件,比如在Linux中的tmp文件目录.那么在我们的snap设计中,我们应该利用哪个文件目录来存储我们的文件呢?答案是我们可以选择XDG_RUNTIME_DIR,当然这也依赖于开发者自己的选择.
我们先来看一下我的一个做好的例程:
https://github.com/liu-xiao-guo/helloworld-fifo
它的snapcraft.yaml文件如下:
在这里,我们设计了一个叫做fifo的应用.它的脚本具体如下:
我首先创建一个目录,并在目录中创建一个文件.显示如下:
显然这个应用的运行是没有任何的permission的问题的.它是完全可以访问并进行读写的位置.这个位置可以被我们的应用程序用来进行FIFO的操作.
我们实际上也可以运行我在应用中的env这个应用来展示所有的环境变量:
当然,我们也可以使用/tmp目录来作为临时存储文件目录.这个目录对于每个snap应用来说都是独特的,也就是每个应用有一个自己的独立的tmp目录.但是我们我们都可以按照/tmp的方式去访问.这个文件的位置可以在我们的桌面电脑的/tmp目录下找到。它的文件目录有点像/tmp/snap.1000_snap.hello.fifo_5BpMiB/tmp。
我们可以使用如下的代码来检验这个:
我们先来看一下我的一个做好的例程:
https://github.com/liu-xiao-guo/helloworld-fifo
它的snapcraft.yaml文件如下:
name: hello version: "1.0" summary: The 'hello-world' of snaps description: | This is a simple snap example that 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 sandboxes binaries * hello-world.sh - enter interactive shell that runs in app sandbox * hello-world - simply output 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: .
在这里,我们设计了一个叫做fifo的应用.它的脚本具体如下:
#!/bin/bash echo "Going to make a directory at: $XDG_RUNTIME_DIR" mkdir -p $XDG_RUNTIME_DIR echo "Create a file at the location..." cd $XDG_RUNTIME_DIR pwd touch thisfile if [ $? == 0 ]; then echo "The file is successfully created!" else echo "The file is not successfully created!" fi
我首先创建一个目录,并在目录中创建一个文件.显示如下:
liuxg@liuxg:~$ hello.fifo Going to make a directory at: /run/user/1000/snap.hello Create a file at the location... /run/user/1000/snap.hello The file is successfully created!
显然这个应用的运行是没有任何的permission的问题的.它是完全可以访问并进行读写的位置.这个位置可以被我们的应用程序用来进行FIFO的操作.
我们实际上也可以运行我在应用中的env这个应用来展示所有的环境变量:
liuxg@liuxg:~$ hello.env | grep XDG_RUNTIME_DIR XDG_RUNTIME_DIR=/run/user/1000/snap.hello
当然,我们也可以使用/tmp目录来作为临时存储文件目录.这个目录对于每个snap应用来说都是独特的,也就是每个应用有一个自己的独立的tmp目录.但是我们我们都可以按照/tmp的方式去访问.这个文件的位置可以在我们的桌面电脑的/tmp目录下找到。它的文件目录有点像/tmp/snap.1000_snap.hello.fifo_5BpMiB/tmp。
我们可以使用如下的代码来检验这个:
fifo
#!/bin/bash echo "Going to make a directory at: $XDG_RUNTIME_DIR" mkdir -p $XDG_RUNTIME_DIR echo "Create a file at the location..." cd $XDG_RUNTIME_DIR pwd touch thisfile if [ $? == 0 ]; then echo "The file is successfully 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 successfully created!"
else
echo "The test.txt file is not successfully created!"
fi
相关文章推荐
- 如何在JSP页面中通过一个按钮,在对话框中选择一个目录而不是选择一个文件;input type=file只能选择一个文件,我想选择一个目录;做不出来项目经理要扣奖金的...............
- 之前账号的文章3:android私有存储目录下的文件如何让其他程序有权限打开
- 希望大牛讨论 树状数据如何选择数据库和设计存储格式
- 用文件的读写和string作为临时存储区复制图片文件
- tomcat文件上传与存储(虚目录、临时存储)
- CMake,如何将临时文件产生到一个特定的目录里面
- android私有存储目录下的文件如何让其他程序有权限打开
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- 如何在VBS脚本中显示“选择文件对话框”或“选择目录对话框”
- FlexBuilder 如何引用其他目录作为工程的src文件件
- 设置 ASP.NET 存储当前应用程序的临时文件(生成的源、编译了的程序集等)的目录的物理路径。
- Qt-编程模块 001: 浏览(选择)、打开 文件和文件夹(目录) --- 如何让按钮**记忆上次打开的文本路径**的功能
- 如何用命令打包一个站点,包括其所有目录文件
- [C#] 如何选择一个目录
- 如何在linux下使用c语言操作临时文件
- VC++中如何遍历整个目录树查找文件
- 临时选择目录对话框
- JAVA 如何创建\删除\修改\复制目录及文件
- 如何获取系统的临时目录路径?
- 如何直接下载保存在Oracl数据库中Blob字段的文件(不生成临时文件)???