问题描述
我正在使用下面的代码:
Cu.import('resource://gre/modules/FileUtils.jsm');
var exe = FileUtils.getFile('XREExeF',[]);
var args ='-P -dev -no-remote';
var name =mysc;
var target = exe;
var cmd =[Desktop Entry] \\\
;
cmd + =Name =+ name +\\\
;
cmd + =Type = Application \\\
;
cmd + =Comment = Web Application \\\
;
cmd + =Exec =+ target.path ++ args +\\\
;
// cmd + =Icon =+ icon.path +\\\
;
Cu.import(resource://gre/modules/osfile.jsm)
var path = OS.Path.join(OS.Constants.Path.desktopDir,'mysc。桌面');
Services.ww.activeWindow.alert(path)
let encoder = new TextEncoder();
let array = encoder.encode(cmd);
let promise = OS.File.writeAtomic(path,array,{tmpPath:file.txt.tmp});
promise.then(
function(aVal){
Services.ww.activeWindow.alert('success aVal ='+ uneval(aVal));
},
函数(aRejReas){
Services.ww.activeWindow.alert('因为原因被拒绝:'+ uneval(aRejReas))
}
)
如何设置chown和chmod?
我发现这个代码
UnixFile .chmod =
declareFFI(chmod,ctypes.default_abi,
* * return * /
Types.negativeone_or_nothing,
/ * path * /
Types.path ,
/ * mode * /
Types.mode_t);
UnixFile.chown =
declareFFI(chown,ctypes.default_abi,$ b $ / * return * /
Types.negativeone_or_nothing,
/ * path * /
Types.path,
/ * uid * /
Types.uid_t,
/ * gid * /
Types.gid_t);
有人告诉我设置 chown noi
和 chmod + x
,因为我的桌面路径是: /home/noi/Desktop/mysc.desktop
会修正这个错误:
也许 OS.File.setPermissions
?
我试过这个,但是没有成功:
var promise2 = OS.File.setPermissions(path,{
unixMode:OS.Constants.libc.S_IRWXO
});
promise2.then(
function(aVal){
console.log('promise2 success','aVal:',aVal);
},
function aReason){
console.warn('promise2 rejected','aReason:',aReason);
}
);
我不知道如何设置chown chmod,但我能够创建该文件作为受信任。它是沿着 OS.File.setPermission
的行,但由于某些原因使用 unixMod
和 OSConstants.libc.S_I *
就像推荐的文档不对。
这是我制作一个值得信赖的桌面快捷方式: / p>
Cu.import('resource://gre/modules/FileUtils.jsm');
Cu.import(resource://gre/modules/osfile.jsm)
var exe = FileUtils.getFile('XREExeF',[]);
var args ='-P dev -no-remote';
var name =Mozilla Firefox - dev;
var target = exe;
var icon_path = OS.Path.join(OS.Constants.Path.desktopDir,'beta.png');
var cmd =[Desktop Entry] \\\
;
cmd + =Name =+ name +\\\
;
cmd + =Type = Application \\\
;
cmd + =Comment = Web Application \\\
;
cmd + =Exec =+ target.path ++ args +\\\
;
cmd + =Icon =+ icon_path +\\\
;
var path = OS.Path.join(OS.Constants.Path.desktopDir,'mysc.desktop');
let encoder = new TextEncoder();
let array = encoder.encode(cmd);
let promise = OS.File.writeAtomic(path,array,{tmpPath:file.txt.tmp});
promise.then(
function(aVal){
console.log('aVal',aVal);
var promise2 = OS.File.setPermissions(path,{unixMode:
promise2.then(
function(aVal){
console.log('promise2 success','aVal:',aVal);
},
函数(aReason){
console.warn('promise2 rejected','aReason:',aReason);
}
);
},
函数(aRejReas){
Services.ww.activeWindow.alert('rejected by reason:'+ uneval(aRejReas))
}
);
注意 0o4777
而不是 OS.Constants.libc.S_IRWXO
,它的奇怪,我没有想到这一切,只是幸运的搜索github代码库。
I'm trying to create a shortcut that launches a profile on the desktop in Linux.
I'm using this code:
Cu.import('resource://gre/modules/FileUtils.jsm');var exe = FileUtils.getFile('XREExeF', []);var args = '-P -dev -no-remote';
var name = "mysc";
var target = exe;
var cmd = "[Desktop Entry]\n";
cmd += "Name=" + name + "\n";
cmd += "Type=Application\n";
cmd += "Comment=Web Application\n";
cmd += "Exec=" + target.path + " " + args + "\n";
//cmd += "Icon=" + icon.path + "\n";
Cu.import("resource://gre/modules/osfile.jsm")
var path = OS.Path.join(OS.Constants.Path.desktopDir, 'mysc.desktop');
Services.ww.activeWindow.alert(path)
let encoder = new TextEncoder();
let array = encoder.encode(cmd);
let promise = OS.File.writeAtomic(path, array, {tmpPath: "file.txt.tmp"});
promise.then(
function(aVal) {
Services.ww.activeWindow.alert('success aVal = ' + uneval(aVal));
},
function(aRejReas) {
Services.ww.activeWindow.alert('rejected for reason: ' + uneval(aRejReas))
}
)
How can i set chown and chmod?
I found this code https://github.com/johnshih/releases-mozilla-aurora/blob/dc29053a4b1765cf94a8562130865036c373038e/toolkit/components/osfile/osfile_unix_back.jsm#L218
UnixFile.chmod =
declareFFI("chmod", ctypes.default_abi,
/*return*/
Types.negativeone_or_nothing,
/*path*/
Types.path,
/*mode*/
Types.mode_t);
UnixFile.chown =
declareFFI("chown", ctypes.default_abi,
/*return*/
Types.negativeone_or_nothing,
/*path*/
Types.path,
/*uid*/
Types.uid_t,
/*gid*/
Types.gid_t);
Someone told me to set chown noi
and chmod +x
on the file because my path to desktop is: /home/noi/Desktop/mysc.desktop
will fix this error here:
Maybe OS.File.setPermissions
?
I tried this but it didnt work:
var promise2 = OS.File.setPermissions(path, {
unixMode: OS.Constants.libc.S_IRWXO
});
promise2.then(
function(aVal) {
console.log('promise2 success', 'aVal:', aVal);
},
function(aReason) {
console.warn('promise2 rejected', 'aReason:', aReason);
}
);
I didn't figure out how to set chown and chmod but I was able to create the file as trusted. It was along the lines of OS.File.setPermission
but for some reason using unixMod
and the flags of OSConstants.libc.S_I*
like the docs recommended was not right.
This is how I made a trusted desktop shortcut:
Cu.import('resource://gre/modules/FileUtils.jsm');
Cu.import("resource://gre/modules/osfile.jsm")
var exe = FileUtils.getFile('XREExeF', []);
var args = '-P dev -no-remote';
var name = "Mozilla Firefox - dev";
var target = exe;
var icon_path = OS.Path.join(OS.Constants.Path.desktopDir, 'beta.png');
var cmd = "[Desktop Entry]\n";
cmd += "Name=" + name + "\n";
cmd += "Type=Application\n";
cmd += "Comment=Web Application\n";
cmd += "Exec=" + target.path + " " + args + "\n";
cmd += "Icon=" + icon_path + "\n";
var path = OS.Path.join(OS.Constants.Path.desktopDir, 'mysc.desktop');
let encoder = new TextEncoder();
let array = encoder.encode(cmd);
let promise = OS.File.writeAtomic(path, array, {tmpPath: "file.txt.tmp"});
promise.then(
function(aVal) {
console.log('aVal', aVal);
var promise2 = OS.File.setPermissions(path, {unixMode: 0o4777});
promise2.then(
function(aVal) {
console.log('promise2 success', 'aVal:', aVal);
},
function(aReason) {
console.warn('promise2 rejected', 'aReason:', aReason);
}
);
},
function(aRejReas) {
Services.ww.activeWindow.alert('rejected for reason: ' + uneval(aRejReas))
}
);
Notice the 0o4777
instead of OS.Constants.libc.S_IRWXO
, its weird, I didn't expect this at all and just got lucky searching github code base.
这篇关于OS.File设置chown和chmod(创建受信任的启动器 - Ubuntu的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!