Best way to save a file using NSDocument? - swift3

I'm encountering problems saving a document as I can see in the debug area:
NSFileVersion tried to tried to add a new generation and failed. Versioned file URL: file:///Users/mike97/Downloads/test%20copy.xml, contents URL: file:///Users/mike97/Downloads/test%20copy~.xml, error: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.069020+0200 XML Parser[2095:54823] NSDocument failed to preserve the old version of a document. Here's the error:
Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.118611+0200 XML Parser[2095:54823] <XML_Parser.Document: 0x6000001014d0>: An error occurred while attempting to preserve the backup file at file:///Users/mike97/Downloads/test%20copy~.xml: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}} ##
The app try to atomically save a file called 'test copy.xml' and doing this just rename that file to 'test copy~.xml', why cannot found the original one. In fact changing the option parameter saving the data the error gone.
This is the code I'm using in my NSDocument subclass:
override func writeSafely(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) throws {
if let vc = self.windowController?.contentViewController as? ViewController {
switch typeName {
case "XML v1":
do {
try vc.parser?.save().write(to: url, options: [])
} catch {
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
break
..
In NSData.WritingOptions we can found some of the options to save a file, but I'm not sure what of them I need. Anyone care to explain me what they are and what are the best using the 'writeSafely' method chosen by me?
Also that method handles possible errors, so that a non-atomic write operation appear to be enough, but I wonder on how can I preserve the 'versioning' functionality by macOS.

Related

NoClassDefFoundError encountered while fixing CRLF sequence in HttpHeader

After performing Vera code scan on my code, a flaw was reported saying " Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting - CWE ID 113') on the below code.
public void writeCookies() {
for (final Cookie cookie : cookies) {
super.addCookie(cookie);
}
The flaw code reported is super.addCookie(cookie). To fix this I added below code
public void writeCookies() {
for (final Cookie cookie : cookies) {
cookie.setSecure(true);
ESAPI.httpUtilities().addCookie(((HttpServletResponse)super.getResponse()),cookie);
}
}
Now the Veracode scan doesn't report any flaw in the code. However, while running the application, I get NoClassDefFoundError as below
Error Message: javax.servlet.ServletException:
java.lang.NoClassDefFoundError:
org.apache.commons.fileupload.FileItemFactory Error Code: 500 Target
Servlet: com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor
Error Stack: java.lang.NoClassDefFoundError:
org.apache.commons.fileupload.FileItemFactory
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:171)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:180)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:74)
at org.owasp.esapi.ESAPI.httpUtilities(ESAPI.java:121)
My ESAPI.properties file is at location src/main/resources/ESAPI.properties
The content of ESAPI.properties file is
*
Encoder.AllowMultipleEncoding=false Encoder.AllowMixedEncoding=false
Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
ESAPI.HTTPUtilities=org.owasp.esapi.reference.DefaultHTTPUtilities
*
Please suggest me on how to fix this NoClassDefFoundError...

No local SparkleFormation files detected

So I've been working in sparkleformation and had this issue pop up even though all my files exist:
[WARN]: No local SparkleFormation files detected
[ERROR]: Failed to locate any templates!
[FATAL]: Invalid formation file path provided:
ERROR: IOError: Failed to locate file:
I wanted to create this question for future reference. This is what happens if you create a sparkleformation template and place any code outside of the Sparkleformation.new block. For example this would cause the above failure:
yamlfile = YAML.load_file(ENV['YAMLFILE_YML_PATH'])
SparkleFormation.new(:somename, :provider => :aws).load(:base).overrides do
yamlfile.keys.each { |key| yamlfile[key.to_sym] = yamlfile.delete(key)}
dynamic!(:someother name, :test_eips, yamlfile)
end
This will work:
SparkleFormation.new(:somename, :provider => :aws).load(:base).overrides do
yamlfile = YAML.load_file(ENV['YAMLFILE_YML_PATH'])
yamlfile.keys.each { |key| yamlfile[key.to_sym] = yamlfile.delete(key)}
dynamic!(:someother name, :test_eips, yamlfile)
end

How can I make file association in Qt installer(1.5.0)?

How can I make file association in Qt installer framework(1.5.0) on Windows? I want to do this:
For example, when I double click myFile.x then my qt desktop application(Windows) will launch and open this file.
I want to correct this in installscript.qs :
component.addOperation("CreateShortcut", "#TargetDir#/A.exe", "#StartMenuDir#/A.lnk");
component.addOperation("RegisterFileType",
"fl",
"#TargetDir#\\A.exe" + "'%1'",
"myFiles",
"text/plain",
"#TargetDir#/A_icon.ico",
"ProgId=A.fl");
component.addOperation("CreateShortcut", "#TargetDir#/uninstall.exe", "#StartMenuDir#/Uninstall.lnk");
When I write this string, it gives parse error.
Output is :
Caught exception: Exception while loading component script: 'D:/Workspace/A/A_installer/A/packages/com.ge.mss/meta/installscript.qs
SyntaxError: Parse error
Backtrace:
()#D:/Workspace/A/A_installer/A/packages/com.ge.mss/meta/installscript.qs:102'
If you are using windows just follow this:
component.addOperation("RegisterFileType",
"bob",
"#TargetDir#\\BobiSoft.exe \" %1\"",
"BobiSoft Files",
"application/x-binary",
"#TargetDir#/bobi_file_icon.ico",
"ProgId=BobiSoft.bob");
I also had this problem, the trick was to replace the ' %1' as many examples say, with \" %1\".

I cannot put file with cfftp, any ideas why?

I am trying to create a function to upload two xml files to another website once a day, I can make a connection fine using this code
<cfftp action = "open"
username = "xxxx"
connection = "MyConnection"
password = "xxxx"
server = "xxx"
passive="yes"
secure="true">
but then when I try to put the file using this code
<cfftp
action="putFile"
connection="MyConnection"
localfile="xxx"
remotefile="xxx">
then I get this error
An error occurred during the sFTP putFile operation.
Error: Permission denied.
The error occurred in xxxxx: line 13
11 : connection="MyConnection"
12 : localfile="xxxx"
13 : remotefile="xxxx">
Additional background info is that I can upload via filezilla.
Just use passive="yes" with the putFile operation:
<cfftp
action="putFile"
connection="MyConnection"
localfile="xxx"
remotefile="xxx"
passive="yes">
I just had a look at some code I wrote a while ago that uses cfftp, and my remotefile contains the full path. Can you confirm if yours does this?
The error "permission denied" would make sense it if was trying to upload it into the wrong directory also. Let us know how you go.

Opencart Vqmod Error Writing Log

I want to ask opencart problem, I got this error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
OK
{"country_id":"100","name":"Indonesia","iso_code_2":"ID","iso_code_3":"IDN" ,"address_format":"","postcode_required":"1","zone":[{"zone_id":"1507","country_id":"100","name":"Aceh","code":"Aceh","status":" 1"},{"zone_id":"1508","country_id":"100","name":"Bali","code":"Bali","statu s":"1"},{"zone_id":"1509","country_id":"100","name":"Banten","code":"Banten ","status":"1"},{"zone_id":"1510","country_id":"100","name":"Bengkulu","cod e":"BE","status":"1"},{"zone_id":"1511","country_id":"100","name":"D.I.Yogy akarta","code":"YG","status":"1"},{"zone_id":"1512","country_id":"100","nam e":"Gorontalo","code":"GO","status":"1"},{"zone_id":"1513","country_id":"10 0","name":"Jakarta","code":"Jakarta","status":"1"},{"zone_id":"1514","count ry_id":"100","name":"Jambi","code":"JA","status":"1"},{"zone_id":"1515","co untry_id":"100","name":"Jawa Barat","code":"JB","status":"1"},{"zone_id":"1516","country_id":"100","name ":"Jawa Tengah","code":"JT","status":"1"},{"zone_id":"1517","country_id":"100","nam e":"Jawa Timur","code":"JI","status":"1"},{"zone_id":"1518","country_id":"100","name ":"Kalimantan Barat","code":"KB","status":"1"},{"zone_id":"1519","country_id":"100","name ":"Kalimantan Selatan","code":"KS","status":"1"},{"zone_id":"1520","country_id":"100","na me":"Kalimantan Tengah","code":"KT","status":"1"},{"zone_id":"1521","country_id":"100","nam e":"Kalimantan Timur","code":"KI","status":"1"},{"zone_id":"1522","country_id":"100","name ":"Kepulauan Bangka Belitung","code":"BB","status":"1"},{"zone_id":"1537","country_id":"100","n ame":"Kepulauan Riau","code":"KPR","status":"1"},{"zone_id":"1523","country_id":"100","name ":"Lampung","code":"LA","status":"1"},{"zone_id":"1524","country_id":"100", "name":"Maluku","code":"MA","status":"1"},{"zone_id":"1525","country_id":"1 00","name":"Maluku Utara","code":"MU","status":"1"},{"zone_id":"1526","country_id":"100","name ":"Nusa Tenggara Barat","code":"NB","status":"1"},{"zone_id":"1527","country_id":"100","name ":"Nusa Tenggara Timur","code":"NT","status":"1"},{"zone_id":"1528","country_id":"100","name ":"Papua","code":"PA","status":"1"},{"zone_id":"3970","country_id":"100","n ame":"Papua Barat","code":"PB","status":"1"},{"zone_id":"1529","country_id":"100","name ":"Riau","code":"RI","status":"1"},{"zone_id":"3971","country_id":"100","na me":"Sulawesi Barat","code":"SR","status":"1"},{"zone_id":"1530","country_id":"100","name ":"Sulawesi Selatan","code":"SN","status":"1"},{"zone_id":"1531","country_id":"100","na me":"Sulawesi Tengah","code":"ST","status":"1"},{"zone_id":"1532","country_id":"100","nam e":"Sulawesi Tenggara","code":"SG","status":"1"},{"zone_id":"1533","country_id":"100","n ame":"Sulawesi Utara","code":"SA","status":"1"},{"zone_id":"1534","country_id":"100","name ":"Sumatera Barat","code":"SB","status":"1"},{"zone_id":"1535","country_id":"100","name ":"Sumatera Selatan","code":"SS","status":"1"},{"zone_id":"1536","country_id":"100","na me":"Sumatera Utara","code":"SU","status":"1"}],"status":"1"}<b>Warning</b>:
file_put_contents(C:\xampp\htdocs\rumahjoy\vqmod/logs/Fri.log) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in <b>/home/sloki/user/h1604/sites/rumahjoy.com/www/vqmod/vqmod.php</b> on line <b>395</b>LOG FILE COULD NOT BE WRITTEN
I have 2 question:
First, what happen with my vqmod? It got C:\xampp (localhost). I've hosted it to server which must be /home/sloki/user/.......
Second, what's wrong with JSON error? Because at localhost it works fine.
Upgrade to VQmod 2.3.2 then its solved..