如何在snap设计中选择文件目录作为临时存储
来源:互联网 发布:虚拟货币网站源码 编辑:程序博客网 时间:2024/06/06 00:47
在我们的应用设计中,我们通过会选择一些临时的文件目录来存储我们的文件,比如在Linux中的tmp文件目录.那么在我们的snap设计中,我们应该利用哪个文件目录来存储我们的文件呢?答案是我们可以选择XDG_RUNTIME_DIR,当然这也依赖于开发者自己的选择.
我们先来看一下我的一个做好的例程:
https://github.com/liu-xiao-guo/helloworld-fifo
它的snapcraft.yaml文件如下:
name: helloversion: "1.0"summary: The 'hello-world' of snapsdescription: | 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 textgrade: stableconfinement: stricttype: app #it can be gadget or frameworkicon: icon.pngapps: 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/writetocommonparts: hello: plugin: dump source: .
在这里,我们设计了一个叫做fifo的应用.它的脚本具体如下:
#!/bin/bashecho "Going to make a directory at: $XDG_RUNTIME_DIR"mkdir -p $XDG_RUNTIME_DIRecho "Create a file at the location..."cd $XDG_RUNTIME_DIRpwdtouch thisfileif [ $? == 0 ]; thenecho "The file is successfully created!"elseecho "The file is not successfully created!"fi
我首先创建一个目录,并在目录中创建一个文件.显示如下:
liuxg@liuxg:~$ hello.fifo Going to make a directory at: /run/user/1000/snap.helloCreate a file at the location.../run/user/1000/snap.helloThe file is successfully created!显然这个应用的运行是没有任何的permission的问题的.它是完全可以访问并进行读写的位置.这个位置可以被我们的应用程序用来进行FIFO的操作.
我们实际上也可以运行我在应用中的env这个应用来展示所有的环境变量:
liuxg@liuxg:~$ hello.env | grep XDG_RUNTIME_DIRXDG_RUNTIME_DIR=/run/user/1000/snap.hello
当然,我们也可以使用/tmp目录来作为临时存储文件目录.这个目录对于每个snap应用来说都是独特的,也就是每个应用有一个自己的独立的tmp目录.但是我们我们都可以按照/tmp的方式去访问.这个文件的位置可以在我们的桌面电脑的/tmp目录下找到。它的文件目录有点像/tmp/snap.1000_snap.hello.fifo_5BpMiB/tmp。
我们可以使用如下的代码来检验这个:
fifo
#!/bin/bashecho "Going to make a directory at: $XDG_RUNTIME_DIR"mkdir -p $XDG_RUNTIME_DIRecho "Create a file at the location..."cd $XDG_RUNTIME_DIRpwdtouch thisfileif [ $? == 0 ]; thenecho "The file is successfully created!"elseecho "The file is not successfully created!"ficd /tmppwdecho "Haha" > test.txtif [ $? == 0 ]; thenecho "The test.txt file is successfully created!"elseecho "The test.txt file is not successfully created!"fi
0 0
- 如何在snap设计中选择文件目录作为临时存储
- Snap Chrome浏览器及展示如何在snap中打入debian包
- 如何在Snap包中定义全局的plug
- 如何在bat文件中设置JAVA临时环境变量
- 临时选择目录对话框
- 如何在JSP页面中通过一个按钮,在对话框中选择一个目录而不是选择一个文件;input type=file只能选择一个文件,我想选择一个目录;做不出来项目经理要扣奖金的...............
- VB中如何获取系统临时目录
- 如何在JasperReports中使用XML文件作为数据源?
- 如何在JasperReports中使用CSV文件作为数据源?
- 在存储过程中使用临时表
- 在存储过程中创建临时表
- 如何获取当前数据库名称及在存储过程中临时设置数据库兼容级别
- 用文件的读写和string作为临时存储区复制图片文件
- 存储过程示例:在存储过程中使用临时表
- 如何在 Linux 中复制文件到多个目录中
- 如何为树莓派安装Ubuntu Core并在Snap系统中进行编译
- 如何利用LXD来在不同的Ubuntu桌面环境中编译我们的snap
- 如何在snap中利用socket.io及websocket来进行实时数据更新
- 迷宫求解最短路径问题java版
- 移动端跨平台开发框架 Cordova 学习笔记(一) 环境搭建及创建第一个 Cordova Android APP
- PDF文件如何修改文字和图片
- shell 中的变量介绍
- 数据结构实验之串一:KMP简单应用
- 如何在snap设计中选择文件目录作为临时存储
- 做外链的方法
- Java面试相关题目 (第一节)
- C# 学习整理——SQLHelper
- intellijidea设置向前和向后快捷键
- Docker相关技术说明
- logstash Codec插件
- Firefox鼠标手势 切换标签组代码 火狐浏览器Tab Groups切换鼠标手势
- 为什么类的定义以分号结束