Hi Bob,
----- Ursprüngliche Mail -----
> Von: "Robert Hanson" <[email protected]>
> An: [email protected]
> Gesendet: Donnerstag, 19. Juli 2012 15:29:55
> Betreff: Re: [Jmol-users] repeated saving/loading of .jmol files
> Great idea, Alexander,
>
> I don't understand the reason for #nnn. If the file is unique, giving
> it the cleaned up new name is fine; if it not unique, we give it the
> other file's name and do that replacement, but we don't add it to the
> files to include in the zip file. The only time we need a unique name
> is if there is a name clash for two files that are different.
>
> Right?
Yes.
>
> I don't want to create special names unless absolutely necessary.
Indeed, that's better.
> Take a look at what I checked in. I think it takes care of it.
>
In line 1289: if (crcMap.containsKey(newName)) {
it should be: if (crcMap.containsValue(newName)) {
I argue the name you create is not necessarily unique:
if (pt > ptSlash) // is a file extension, probably
newName = newName.substring(0, pt) + "[" + iFile + "]" +
newName.substring(pt);
else
newName = newName + "[" + iFile + "]";
three files, A and B have the same content, C differs
fileNameA (iFile=1): "foo"
fileNameB (iFile=2): "bar"
fileNameC (iFile=3): "foo[1]"
maybe instead:
if (pt > ptSlash) // is a file extension, probably
newName = newName.substring(0, pt) + "#[" + iFile + "]" +
newName.substring(pt);
else
newName = newName + "#[" + iFile + "]";
now there is the "#" character to ensure uniqueness as the character can only
occur in when we add it - for that we also need to replace the "#" character
for all new file names as done in line 1270: newName =
TextFormat.replaceAllCharacters(newName, "#", "_"); Well, now we are back at
creating special names for all files (no "#" characters), with that I'm ok
though. Some character sequence such as "#####" would make it more unlikely to
taint innocent file names.
Best
Alex
> Bob
>
>
>
> On Wed, Jul 18, 2012 at 8:40 AM, Alexander Rose <
> [email protected] > wrote:
>
>
> Hi,
>
> attached is a small patch that changes zip file creation
>
> - use just the file name of files inside a zip file loaded from an URL
> with getParams ("?") instead of the whole URL
> - append an unique id to files inside a zip file collection
> - when adding files to a zip file collection test if a file with an
> identical content has already been added and if so use that file
> instead
>
>
>
>
>
>
> Best
> Alex
>
>
> ----- Ursprüngliche Mail -----
> > Von: "Alexander Rose" < [email protected] >
> > An: [email protected]
> > Gesendet: Dienstag, 17. Juli 2012 20:32:46
> > Betreff: [Jmol-users] repeated saving/loading of .jmol files
>
>
> > Hi,
> >
> > I have a problem with saving and loading PNGJ state files to and
> > from
> > a web server. I load a pdb from the web server
> > ( http://host/path?getParams=pdb ) and save it via the
> > ?POST?_PNGJBIN_
> > request feature. For the zip file collection the pdb file name gets
> > translated to "http___host_path_getParams_pdb". The I load the PNGJ
> > from the server ( http://host/path?getParams=pngj1 ). The pdb file
> > is
> > loaded from the zip inside the pngj as
> > " http://host/path?getParams=pngj1|http___host_path_getParams_pdb ".
> > When I again save it ( http://host/path?getParams=pngj2 ) the pdb
> > file
> > name gets now translated to
> > "http___host_path_getParams_pngj1|http___host_path_getParams_pdb".
> > Upon loading pngj2 Jmol chokes on the new path, presumably because
> > of
> > the "|", at least when I added the "|" to the characters that get
> > replace when creating the new file name (see below), loading of
> > pngj2
> > works. Also of note is that the pdb file name gets longer every time
> > the pngj is loaded/saved. The root problem is that the
> > special case of getParams ("?" character) plus loading from within a
> > zip file ("|" character) is not handled. I have a solution below.
> >
> > I haven't experienced it yet but how I understand the code, files
> > with
> > the same name are presumed identical and only the first is added to
> > the zip file. I suggest to append the file index to the file name to
> > make it unique and test for identical files with a hash function.
> >
> >
> > jmol.viewer.FileManager.java::createZipSet()
> >
> > String newName = name;
> > if (newName.indexOf("?") > 0) // I guess this is to catch urls which
> > do not have something like a file name but get params
> > newName = TextFormat.replaceAllCharacters(newName, "/:?\"'=&", "_");
> > // newName = TextFormat.replaceAllCharacters(newName, "|/:?\"'=&",
> > "_"); // quick fix by adding "|", see above, no solution
> > else
> > newName = stripPath(name);
> >
> > where stripPath is:
> >
> > private static String stripPath(String name) {
> > int pt = Math.max(name.lastIndexOf("|"), name.lastIndexOf("/"));
> > return name.substring(pt + 1);
> > }
> >
> >
> >
> > // suggested replacement to ensure filename uniqueness and fix
> > growing
> > filenames
> > String newName = name;
> > if (newName.indexOf("?") > 0 && !(newName.indexOf("|") > 0))
> > newName = TextFormat.replaceAllCharacters(newName, "/:?\"'=&", "_");
> > else
> > newName = stripPath(name);
> >
> > newName = TextFormat.replaceAllCharacters(newName, "#", "_");
> > if (newName.indexOf(".") >= 0)
> > newName = newName.substring(0, newName.lastIndexOf(".")) + "#" +
> > iFile
> > + newName.substring(newName.lastIndexOf("."));
> > else
> > newName = newName + "#" + iFile
> >
> >
> > with that we have
> > - unique file names
> > - non growing file names
> > - good preserving of original file names or info where it came from
> >
> >
> > I also started testing for unique files based on the CRC value, but
> > sort of forgot that it had to be decide before replacing the new
> > file
> > names in the state... tomorrow. I'll wait for comments, then create
> > a
> > patch.
> >
> >
> > Best
> > Alexander
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond.
> > Discussions
> > will include endpoint security, mobile security and the latest in
> > malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Jmol-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/jmol-users
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>
>
>
> --
> Robert M. Hanson
> Larson-Anderson Professor of Chemistry
> Chair, Chemistry Department
> St. Olaf College
> Northfield, MN
> http://www.stolaf.edu/people/hansonr
>
>
> If nature does not answer first what we want,
> it is better to take what answer we get.
>
> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users