Commit Graph
40 Commits
Author SHA1 Message Date
dotCooCoo cc2c5c770f Bound XMP metadata work and preserve packet boundaries 2026-11-26 19:15:16 -08:00
dotCooCoo 0669a4525a Merge main into feat/scripts-xmp-objects 2026-11-26 15:20:19 -08:00
dotCooCoo bb439ce33b Merge main into feat/scripts-xmp-objects
XMP updates flush their destination folders on Unix. The host records completed writes and refreshes open readers before reporting a folder flush error. XMPFile retains its pending packet for retry.
2026-11-26 13:45:26 -08:00
dotCooCoo 051781e23d Merge main into feat/scripts-xmp-objects
Keep XMP file buffers in native state and release them at the file run boundary. Count registered namespaces and expanded metadata against the heap limit. Reset marked readers after updates and allow failed library setup to retry.
2026-11-26 13:13:53 -08:00
dotCooCoo 2fc172e69a Merge main into feat/scripts-xmp-objects 2026-11-25 22:11:49 -08:00
dotCooCoo 6ad8c0476a Scripts: script.grants.revoke removes only the grant named as given
script.grants.revoke matched a path both as given and with its links
followed, so revoking a grant whose path is now a link to another
granted path removed both grants. The spellings are now tried in order,
the path as given first, and only the first script and path pair that
some grant holds is removed.
2026-11-25 15:13:55 -08:00
dotCooCoo 73978a194f Scripts: script.grants.revoke matches a path as given as well as resolved
A grant whose path a link has since replaced is listed by script.grants
under the path it was kept for, but script.grants.revoke followed the
link and compared the link's target, so Revoke in Script File Access
removed nothing. A path is now matched as given and, inside the
automation read roots, also with its links followed.
2026-11-25 10:00:05 -08:00
dotCooCoo 1ac56ef3ba Scripts: script.grants reports a grants file that is a link to a missing file
A link in the grants file's place whose target is missing is there but
cannot be read, so script.grants fails on it and script.grants.revoke
leaves it as it is, instead of treating it as a missing grants file.
2026-11-24 17:54:20 -08:00
dotCooCoo 6d0d4bd1a4 Merge main into fix/script-grants-read-failure 2026-11-24 17:26:58 -08:00
dotCooCoo a0cc0230b0 Scripts: an XMP sidecar update flushes the packet first and goes through on volumes without Unix permissions
- closeFile() flushes the temporary file to the disk with vectorcraft_format::sync_file before it
  takes the sidecar's name, as a saved document's temporary file is flushed.
- Keeping the sidecar's permissions is best effort, as in write_atomic: a volume that refuses Unix
  permissions (SMB, FAT) no longer makes every update throw "Script file could not be written".
- docs/mcp.md says both.
2026-11-22 16:52:35 -08:00
dotCooCoo 06d430e4bd Scripts: a replaced XMP sidecar keeps its group and access ACL
closeFile() now replaces a sidecar through vectorcraft_format::keep_permissions, the same step a
saved document takes. On Unix the temporary file takes the sidecar's permission bits, group and (on
Linux) access ACL, or stays readable by its owner alone where the group or the ACL cannot be kept.
Permission bits that cannot be set fail the write, and the sidecar stays as it was. A Linux test
checks that a folder's default ACL does not reach a replaced sidecar.
2026-11-22 16:01:53 -08:00
dotCooCoo 2894c60473 Scripts: XMP packets are checked as they are read and written, and safe closes use a temporary file
- closeFile with XMPConst.CLOSE_UPDATE_SAFELY passes the flag to xmpWrite, which then writes only
  through a temporary file; where none may be made it throws and leaves the sidecar and the packet
  as they are.
- On Unix the temporary file is created with mode 0600 and takes the sidecar's permission bits
  after the packet is written.
- canPutXMP and putXMP check again that the file is open for update after converting the packet
  argument, since a toString may close it.
- Path arguments are converted once, so a toString that changes between calls cannot mix two
  paths.
- setLocalizedText moves an existing x-default item to the front.
- A second ExternalObject install is refused and keeps the registered namespaces.
- Text beside rdf:Description elements or their properties makes a packet malformed.
- Properties read from a packet share one copy of each namespace URI, and reading stops once the
  properties exceed the script heap.
- A value with qualifiers in the rdf:value form gives the text and options of its rdf:value, and
  an empty property element whose attributes are fields is a structure.
- serialize() and reading refuse a value that would be written with more than 1,024 attributes or
  namespace declarations in scope at one element.
- find_packet treats packet markers inside CDATA sections and comments as text, and passes over a
  packet that is not UTF-8 for the next one. A section that holds a trailer and then a start does
  not hide that start, and each marker search starts where the last one stopped, so the scan
  reads the bytes about once.
- An rdf:Alt item with xml:lang="" has no language, so its array is not a language alternative;
  the empty attribute is written back as it was.
- The rdf:about value counts toward the parse budget, also in a packet with no properties.
- docs/mcp.md says that the prefix limit applies to a namespace being registered.
- The round-trip property test generates valid packets, the retry test closes the same XMPFile
  again after a failed write, and the heap-limit test requires a heap-limit error and a change
  that goes through.
2026-11-22 13:40:36 -08:00
dotCooCoo 58dab25cc6 Scripts: a sidecar XMPFile replaces keeps its Unix permission bits
closeFile() writes a sidecar through a new temporary file and renames it
over the sidecar, so a 0600 sidecar became 0644 under a 022 umask. The
temporary file now takes the sidecar's permission bits before the
rename, as File.copy does for its target.

Test: a_replaced_sidecar_keeps_its_permissions (Unix only) in
crates/engine/src/tests/script_xmp.rs.
2026-11-22 08:11:31 -08:00
dotCooCoo 8cc1bc8530 Scripts: ExternalObject loads the XMP objects XMPMeta, XMPFile and XMPConst
new ExternalObject("lib:AdobeXMPScript") defines XMPMeta, XMPFile and
XMPConst in the script engine; any other library name throws and no
native library is loaded.

- XMPMeta reads a packet string and serializes one, with or without the
  packet wrapper: simple properties, arrays of simple items, language
  alternatives and namespace registration and lookup. Structures and
  values with qualifiers are kept as they were written.
- XMPFile reads and writes only where File may. A .xmp sidecar opened
  for update takes putXMP, and closeFile writes it through a temporary
  file in the same folder when the script may write there; other files
  are scanned for their packet and are read only. File's 8 MiB limit
  applies before reading.
- Packets are parsed with craft-xml: a document type declaration, an
  undefined entity, nesting over 64 levels and a packet over 8 MiB are
  refused with an error.
- Members not built yet (iterators, structure fields, qualifiers,
  aliases, sorting, byte-array packets, XMPFile.getFormatInfo) throw
  that they are not available yet.

The XMPConst flag values follow the public XMP Toolkit SDK header
XMP_Const.h. Tests: crates/js/src/xmp_tests.rs, with fuzz cases for the
packet parser and scanner, and crates/engine/src/tests/script_xmp.rs.
Docs: docs/mcp.md and docs/target-app-parity.md.
2026-11-22 06:11:31 -08:00
dotCooCoo dc9a724b6a Merge main into fix/script-export-linked-files 2026-11-21 21:04:37 -08:00
dotCooCoo ceab5d7e11 Merge main into fix/script-grants-read-failure 2026-11-21 20:33:50 -08:00
dotCooCoo 29ddc57821 Scripts: what a script's commands open or change gives later runs no file access
The commands a script runs could read the files that the documents open
at the run's start link to, and could read and write the files of every
open document. Both lists were taken from the documents as they were, so
a document a script opened, or a link or data set value a script added,
widened what the next run could read, and a document opened from a
linked file could be saved over that file in the next run.

- DocState::by_script records what scripts' commands did to a document
  since the person last opened or saved it: opened it, or changed it or
  gave it another file, keeping the document, its file and the file it
  was read from as they were before. The script host notes it after
  every command, and a save the person makes from the document's current
  content clears it. Revert keeps it, and a recovery copy restores the
  document as one a script opened.
- The gate's document files and the linked files are taken from each
  document as the person left it (DocState::as_person_left). A document
  a script opened gives neither, in that run or a later one.
- This replaces the per-run record of paths read through the linked
  files and ScriptGate::keeping_linked_read_only.
- docs/mcp.md and docs/target-app-parity.md describe the rule.
2026-11-21 02:45:27 -08:00
dotCooCoo bab25d0248 Scripts: a document opened from a linked file stays read-only when its path changes
The gate now records each path a script's command reads only because it led
to a file the open documents link to. A document whose file is such a path is
taken out of the open documents' files for the rest of the run, without
looking at where the path leads now or what the script may read now. Before,
the gate decided that again for each command from the path's current target,
so a path pointed at another file by a link, or a read grant given later,
let the run read and write through the document.
2026-11-21 01:32:08 -08:00
dotCooCoo 9758ece7ef Scripts: vc.run export of an open document reads its own linked files
A command a script runs with vc.run could read only the script's own places
and the open documents' own files, so an export, save, print or package of
a document whose linked images or placed files sit elsewhere fell back to
the saved previews.

The script gate now also reads, and never writes, the files that the
documents open when the run began link to: linked images, placed files, the
plate files of a DCS image and the images their data sets name. The list is
taken once, at the run's first vc.run, from those documents as they were
when the run began, and holds real paths, so a path that leads to another
file later is refused. A link the script adds or re-points, a path it names
itself and a document it opens give it no further file to read, a document
it opens from one of these files is not saved over it, and the automation
read roots and the name and traversal rules still apply first.
2026-11-21 00:07:34 -08:00
dotCooCoo 999521e391 Scripts: File.hidden can be set and File.createAlias makes a link within the grants
On macOS and Linux, setting `hidden` renames the file or link in its folder with
one leading dot added, or its leading dots taken off. Both the old and the new
name must be places the script may write, and a name of dots alone, a name in
use and a folder are refused. A file the object has open stays open at the new
path.

`createAlias(target)` makes a symbolic link at the object's path to the real
path of a file the script may read. The link's place must be one the script may
write where nothing is, a link that leads nowhere included; the settings folder
is refused for both. When a folder above the link's place is replaced by a link
while the alias is made, the new link is removed and the call fails. `hidden`
reads a link's own name, and setting `hidden`, `rename` and `remove` act on the
link itself.

On Windows both still set `error` and change nothing. `execute` stays
unavailable.

Behavior: https://extendscript.docsforadobe.dev/file-system-access/file-object/
and https://extendscript.docsforadobe.dev/file-system-access/using-file-and-folder-objects/
2026-11-20 21:38:37 -08:00
dotCooCoo 153f6c0750 Scripts: script.grants reports an error when the grants file cannot be read
script.grants listed no grants when Script Grants.json was there but
could not be read, was larger than 4 MiB, did not parse, had another
version or held no list of grants, or when its lock could not be taken.
It now returns "the script file permissions could not be read: {e}" in
those cases, as script.grants.revoke already fails on such a file. A
missing grants file still lists none, and a grant in the file that is
not well formed is still left out.

The run-time grant lookup keeps reading such a file as holding no grants.
The new message has a row in every complete-message catalog. The params
text, docs/mcp.md and the Scripts line in docs/target-app-parity.md state
the error.
2026-11-20 20:23:01 -08:00
dotCooCoo 6c5e10fd64 Color Settings: keep script gates and background reads after a profile answer
- A scope narrowed to the confirming caller keeps the script gates of both,
  and reads are exempt from them only where both scopes exempt them.
- A file read off the UI thread does the rest of its read after its profile
  answer (linked files and type) off the UI thread too; an open a caller
  asked for by path still finishes before OK returns.
2026-11-18 16:46:24 -08:00
dotCooCoo af09fc2064 Scripts: open files are written in the order they were opened
When two File objects held changes to the same file, copy, length, a
new open of the file and a withdrawn grant wrote them in no fixed
order, so the copy or the file could end up with the older object's
bytes. They now write them in the order the objects were opened, as
the end of the run does.
2026-11-17 07:14:42 -08:00
dotCooCoo 8620f0611c Scripts: a file whose write fails after it was emptied is named as written
Writing an open file's bytes empties the file first. When the write then
failed, for example on a full disk, the file had lost its old bytes but
was left out of the files the run names as written. It is now named as
soon as it has been opened for the write.
2026-11-14 15:37:25 -08:00
dotCooCoo b173bd7b40 Scripts: a folder renamed under another case of its name moves its open files
`rename` matched open File objects by the path as given, while the objects
hold the names the file system keeps. Where case does not matter, a folder
named in another case was renamed but its open files kept the old path, so
their changes could not be written and they stayed under the old path's
rules for reading. The objects are now matched by the kept name, and a
rename whose kept name cannot be learned is refused.
2026-11-14 15:00:12 -08:00
dotCooCoo 82620a1b27 Scripts: copy and length reach files open for reading
A file opened with open('r') kept its old bytes after copy wrote over it
or length changed it, while an object open for writing took the new
bytes. Both now update every object that holds the file. An object
that holds a renamed file is found at the new path, and an object whose
file was removed is not taken for a file made later at its path.
2026-11-14 13:19:25 -08:00
dotCooCoo 1ae70095cc Scripts: the grants-file lock waits a bounded time
Taking the lock on Script Grants.lock blocked until the holder let go,
so another process that stalled while holding it stopped listing,
loading, keeping and revoking grants for good. The lock is now tried 20
times, 50 ms apart, and then fails with TimedOut: a change is not made
and a read gives no grants rather than reading without the lock.
2026-11-14 13:06:54 -08:00
dotCooCoo d435ae1a27 Scripts: an open file that is renamed is read under its new path's rules
`rename` moved the write path of open File objects but left the path they
were read from at the old name. When new code then withdrew the kept grant
for the folder, a grant the run still held for the old path let the object
go on giving the file's bytes. The read path now moves with the write path.
2026-11-14 12:42:21 -08:00
dotCooCoo cefaeefca9 Scripts: grants kept earlier in a run keep the code evaluated before a later one
Keeping a second grant with Always marked all the code the run had
evaluated as recorded, so the run's end skipped the grants kept before
it, and they kept the code list from when they were kept. The next run
that evaluated that code withdrew them. Keeping a grant now writes the
current code list into the grants the run kept before it as well.
2026-11-14 12:38:25 -08:00
dotCooCoo 64662b435b Scripts: a file opened under a withdrawn grant is not read
When a run evaluated code that withdrew a kept grant, a File opened under that grant still gave the bytes it held to read, readln and readch, and seek to the end showed its length. Those calls now give Script file access denied and set error, and eof is true. docs/mcp.md says so.
2026-11-13 20:34:27 -08:00
dotCooCoo b73c9834c8 Scripts: grants file changes take turns and use a file of their own
Two processes that changed Script Grants.json at once both wrote Script Grants.json.part, so one could overwrite the other's file or fail on it. Each write now goes to a new file named for its process and write, passing over a name an earlier write left behind, and only that file is removed when the write fails. Changes hold a lock on Script Grants.lock beside the grants file and are not made when it cannot be taken; reads take it when they can.
2026-11-13 19:08:44 -08:00
dotCooCoo 9811cafc25 Scripts: copy reads its source under the rules for reading
copy read the source's real path as it was when looked up, so a file replaced by a link before the read could copy a file from outside the script's places, and a link given as the source that was pointed elsewhere copied the old target. copy now reads the path as given through the same checks open uses and refuses the copy with Script file access denied when the path no longer leads to the file it was looked up as.
2026-11-13 15:39:59 -08:00
dotCooCoo fb12ddb759 Scripts: a renamed file's old path is named in the report's written
rename named only the new path in written, so a run that renamed a file an earlier run wrote did not name the path it emptied. It now names both, as remove names the path it deletes.
2026-11-13 15:06:11 -08:00
dotCooCoo dbfffc8ecb Scripts: commands read through the gate in runs the person starts, and the grants file is not written over when it cannot be read
- A command a script runs reads only where the script may, also in a run the person started; only
  reads of the app's own folders inside the command are exempt.
- Always and script.grants.revoke leave a grants file they cannot read as it is, and fail.
- script.grants names a path outside the automation read roots by its file name alone.
- copy reads the source once, within the 8 MiB limit, writes those bytes, and gives the copy the
  source's permissions.
- write joins its values as UTF-16 before making them text, so a surrogate pair split between two
  values is one character.
2026-11-13 10:09:27 -08:00
dotCooCoo eb1f29f94b Scripts: a script in the settings folder reads only its own file there
A script run from a file directly in the settings folder could read every
file in that folder, Script Grants.json included, because its own folder
was left open inside the fence. Only folders below the settings folder
stay open now, and a script in the settings folder itself reads only its
own file there.
2026-11-13 07:56:02 -08:00
dotCooCoo 4716646c6b Scripts: File and Folder objects write files inside a script's scope, with per-script grants and pickers
A script's File and Folder objects now open files for writing, appending
and editing, and copy, rename, remove and create files and folders. A
script reads and writes its run's temporary folder (Folder.temp) and its
own data folder (Folder.userData), kept between runs for a script run
from a file and inside Folder.temp for a script given as text. It reads
its own folder, and reaches other places only through File.openDialog,
File.saveDialog, Folder.selectDialog and the objects' openDlg, saveDlg and
selectDlg.

- A file dialog asks first. The person picks the file or folder with
  Choose..., then allows it once or, for a script run from a file, always.
  A kept grant is bound to the script's path, the SHA-256 of its text and
  every source the run evaluated. It is withdrawn when a later run of the
  script evaluates other code, including code an earlier run left in the
  same named engine. It stays on the real path that was granted, so a
  link put in that place later does not carry it elsewhere.
- A dialog's filter is a string of file types or a function that is
  called with each file picked; multiSelect gives an array of the files
  picked, at most 2,048, and the dialog says when more were left out.
- A folder's selectDlg opens the host's folder dialog in that folder,
  also where the host shows file dialogs in line. Enter in the file
  dialog denies, unless it goes to the focused Choose... button.
  script.grants.revoke is refused with the busy error while a script
  runs, as the run keeps the grants it started with.
- The paths a file dialog allows come only from the host's file dialog:
  ui.dialog.set cannot set them. Only the person at the keyboard allows
  access; Allow Once and Always Allow sent by automation are refused. The
  dialog describes the access the run asked for, whatever its fields say.
- No grant reaches the settings folder, also when the script's own folder
  holds it.
- A file left open is not written through a link put in place of its
  folder since it was opened, and Folder.userData is null when the data
  folder or the script's folder in it is a link.
- copy onto another link to the same file (a hard link) leaves the file's
  bytes as they are, after the source's open objects have written what
  they hold. Files are compared by identity (device and inode on Unix,
  volume and file index on Windows).
- Folder.temp and Folder.userData check each folder they make against the
  automation write roots first, and Folder.create() makes nothing when a
  missing folder above the target is outside the places the script may
  write.
- An open file holds at most 8 MiB, a run writes at most 32 MiB and keeps
  at most 256 files open, and the files a run left open are written in
  the order they were opened. Setting length and copying a file count the
  bytes every open object of that file takes, and write checks the joined
  text against the limit while joining it. The report names at most 4,096
  written files and sets writtenMore when there were more.
- Errors a script sees are translated in every complete message catalog.
2026-11-13 05:42:56 -08:00
dotCooCoo 19ed0889b1 Merge main into fix/script-files-followups
# Conflicts:
#	crates/engine/src/script/files.rs
2026-11-11 18:48:18 -08:00
dotCooCoo 5bd1bbf536 Scripts: File and Folder exists checks the kind, encode keeps slashes, every call is counted
- `File.encode` and `Folder.encode` leave `/` unescaped, as the File
  object reference lists it among the characters kept
  (https://extendscript.docsforadobe.dev/file-system-access/file-object/).
- `exists` is true for a `File` only when the path names something
  other than a folder, and for a `Folder` only when it names a folder.
- Fields of the records the app returns are read as own properties, so
  a property a script puts on `Object.prototype` does not turn a
  successful `open` into a failure.
- `File.encode`, `File.decode`, `File.isEncodingAvailable` and the
  `Folder` locations count as file calls and charge the host-call limit.
- On the web the locations are `null` and `File.tempName` names a file
  at the root, without asking the platform for a temporary folder.
2026-11-11 14:46:43 -08:00
dotCooCoo 7fbac74885 Merge main into feat/script-target-engine 2026-11-11 12:09:30 -08:00
dotCooCoo b7a6196994 Scripts: File and Folder read files in the script's own folder
Scripts get the File and Folder classes as built-ins of the script
engine. A script run from a file can test whether files exist, read
their properties, list folders with getFiles (a mask or a function),
and open files to read them with read, readln, readch, seek and tell.

- Reads stay inside the script's folder and, when automation read
  roots are set, inside them too. A script given as text reads no
  files. Network and device paths, and paths outside the folder by
  their names, are refused before anything is looked up. Links and
  junctions that lead out are refused, and getFiles leaves them out.
- The encoding comes from the byte order mark, then the encoding the
  script set, then UTF-8 when the bytes are valid, then CP1252.
- Limits: 8 MiB a file, 32 MiB a run, 256 files open at once, 2,048
  getFiles entries and 65,536 names looked at, and paths of at most
  32,767 characters.
- Writing, the file dialogs and execute are not available yet: they
  return false or null and set error.

The report's hostCallCounts gains fileCalls and fileExecutes.
Docs: docs/mcp.md, docs/target-app-parity.md.
2026-11-11 07:46:33 -08:00